I'm having trouble with accessing UniData data from the u2.net toolkit. I'm able to connect ok - have tested connections with the "Test Connection Tool" and in code, both connections work fine. My problem is when I try and fill a dataset - using the sample code: I get this error:
[U2][UCINET][UNIDATA]:You have no privilege on file THENAME
Here is the code:
U2Connection con = new U2Connection();
try
{
U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
conn_str.UserID = "id";
conn_str.Password = "pwd";
conn_str.Server = "srv2";
conn_str.Database = "DB.XXX";
conn_str.ServerType = "UNIDATA";
conn_str.RpcServiceType = "udserver";
con.ConnectionString = conn_str.ToString();
con.Open();
DataTable schema = con.GetSchema();
U2DataAdapter da = new U2DataAdapter("SELECT * FROM THENAME ", con);
DataSet ds = new DataSet();
da.Fill(ds);
}
catch (Exception ex)
{
string lStr = ex.Message;
}
finally
{
con.Close();
1 more note, I have an ODBC connection setup. Through ODBC I can use the same credentials inside a SQL Server Linked Server to access the same query successfully.
Any Ideas would be appreciated.
By default, UniData grants no privileges to access files via SQL.
You will need to run CONVERT.SQL from the database to grant privileges to the file.
You can find out more about the command by either running HELP CONVERT.SQL on the command line, or reading the manuals.
Could you please run TCL command ?
select * from privilege;
Do you see THENAME there? For example, see enclosed screen shot for VOC file.
Related
I am trying to connect to my SQL Server database. I am using C#. Here is my code:
string connectionString = #"Server = tcp:<myLocalIP>, 1433; Initial catalog = <DatabaseName>;
User Id = <User>; Password = <Passwd>;",
queryString = "SELECT * FROM [...]";
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand SelectCommand = new SqlCommand(queryString, connection);
SqlDataReader myreader;
connection.Open();
myreader = SelectCommand.ExecuteReader();
List<String> lst = new List<String>();
while (myreader.Read())
{
lst .Add(myreader[0].ToString());
}
connection.Close();
But connection.Open() throws an error:
SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0).
My server is started, it allows remote connections and TCP/IP is enabled. Any ideas?
DBMSSOCN=TCP/IP is how to use TCP/IP instead of Named Pipes.
Try to change :
string connectionString = #"Server = tcp:<myLocalIP>, 1433;Network Library=DBMSSOCN; Initial catalog = <DatabaseName>;
User Id = <User>; Password = <Passwd>;"
If it won't work, try to hard core IP as in below example :
string connectionString = "Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;
Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword";
For more informations: Connection Strings
Hope that will solve problem, cheers
I found a solution. I created a server(Console Application) that connects to MySQL server. Then I connected my Xamarin/ASP.NET application to that server where I process queries.
I don't know how to programmatically create Crystal Reports OLE DB (ADO) connection with provider Microsoft Office 12.0 Access Database Engine like what I did in this image
OLE DB (ADO)
I need to specify Jet Database password programmatically Jet Database Password
Note : when I use
Dim reportDocument As New ReportDocument()
reportDocument.Load(" MY REPORT PATH ")
reportDocument.SetDatabaseLogon("Admin","Password")
this method sets password from "Jet Database Password" image ... I don't need to set password I need to set Jet database password
I am using following code to pass the jet database password using crystal reports 13 API: (m_repDoc is the report object)
TableLogOnInfo logonInfo = new TableLogOnInfo();
foreach (Table table in m_repDoc.Database.Tables)
{
logonInfo = table.LogOnInfo;
logonInfo.ConnectionInfo.ServerName = server; // path to database file
logonInfo.ConnectionInfo.LogonProperties.Add(new NameValuePair2(
"Jet OLEDB:Database Password", password)); // Your jet database password
table.ApplyLogOnInfo(logonInfo);
}
Of course this is written nowhere in the manuals/help files. It should also work if you are using subreports.
try
{
ReportDocument r = new ReportDocument();
r.Load(path + rptname);
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument boReportClientDocument;
CrystalDecisions.ReportAppServer.DataDefModel.Database boDatabase;
CrystalDecisions.ReportAppServer.DataDefModel.Tables boTables;
CrystalDecisions.ReportAppServer.Controllers.DatabaseController boDatabaseController;
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo boConnectionInfo;
CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag boAttributesPropertyBag;
CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag boLogonPropertyBag;
boReportClientDocument = r.ReportClientDocument;
boDatabaseController = boReportClientDocument.DatabaseController;
boDatabase = boDatabaseController.Database;
boTables = boDatabase.Tables;
foreach (CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable boTableOld in boTables)
{
CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable boTableNew = boTableOld.Clone(true);
boConnectionInfo = boTableNew.ConnectionInfo;
boAttributesPropertyBag = (CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag)boConnectionInfo.Attributes;
// Change the attributes and QE_LogonProperties to an ODBC connection
boAttributesPropertyBag["QE_ServerDescription"] = dbpath;
boLogonPropertyBag = (CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag)boAttributesPropertyBag["QE_LogonProperties"];
boLogonPropertyBag["Data Source"] = dbpath;
boLogonPropertyBag["Jet Database Password"] = "54321";
boAttributesPropertyBag = (CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag)boConnectionInfo.Attributes;
boTableNew.QualifiedName = boTableNew.Name;
boTableNew.ConnectionInfo.UserName = "Admin";
boTableNew.ConnectionInfo.Password = "";
boDatabaseController.SetTableLocation(boTableOld, boTableNew);
}
r.VerifyDatabase();
crystalReportViewer1.ReportSource = r;
crystalReportViewer1.Refresh();
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
you can add it to your App or Web config as keys like:
<add key="ServerName" value="YourServer"/>
<add key="DataBaseName" value="WorkingDataBase"/>
<add key="DatabaseUser" value="DBUser"/>
<add key="DatabasePassword" value="DBPassword"/>
and call them in your code like:
Dim SERVER_NAME As String = ConfigurationManager.AppSettings("ServerName").ToString()
Dim DATABASE_NAME As String = ConfigurationManager.AppSettings("DataBaseName").ToString()
Dim DatabaseUser As String = ConfigurationManager.AppSettings("DatabaseUser").ToString()
Dim DatabasePassword As String = ConfigurationManager.AppSettings("DatabasePassword").ToString()
and for security issue you can encrypt the password and decrypt it.
I'm trying to use the SqlFileStream object in a WCF service to get a handle to a specific file that is in a SQL Server 2012 FileTable. I'm able to get the path and transaction context like you would expect with no issues using this piece of code:
using (SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["FileStorage"].ConnectionString))
{
con2.Open();
string getFileHandleQuery = String.Format(
#"SELECT FileTableRootPath(), file_stream.GetFileNamespacePath(), GET_FILESTREAM_TRANSACTION_CONTEXT()
FROM {0}
WHERE stream_id = #streamId", "FSStore");
byte[] serverTransactionContext;
string serverPath;
using (SqlCommand sqlCommand = new SqlCommand(getFileHandleQuery, con2))
{
sqlCommand.Parameters.Add("#streamId", SqlDbType.UniqueIdentifier).Value = new Guid(finalFileHandleStreamId);
using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
{
sqlDataReader.Read();
serverPath = String.Concat(sqlDataReader.GetSqlString(0).Value, sqlDataReader.GetSqlString(1).Value);
serverTransactionContext = sqlDataReader.GetSqlBinary(2).Value;
sqlDataReader.Close();
}
}
con2.Close();
}
However, once I try and actually use the path and transaction context to create a new SqlFileStream:
using (SqlFileStream dest =
new SqlFileStream(serverPath, serverTxn, FileAccess.Write))
{
...
}
The above blows ups with the following exception: The mounted file system does not support extended attributes.
Can someone please explain to me what I'm doing wrong here?
Thanks!
If you are trying to use FileTable and receive an error when new a SqlFileStream object, please check the filePath value.
SqlFileStream sfs = new SqlFileStream(filePath, objContext, System.IO.FileAccess.Read); <-- Error "The mounted file system does not support extended attributes"
Correct way to obtain the filePath value is
SELECT [file_stream].PathName() FROM dbo.fTable WHERE name = 'test.xlsx'
filePath value should look like:
\\HOSTNAME\MSSQLSERVER\v02-A60EC2F8-2B24-11DF-9CC3-AF2E56D89593\test\dbo\fTable\file_stream\A654465D-1D9F-E311-B680-00155D98CA00\VolumeHint-HarddiskVolume1
not like:
\\HOSTNAME\MSSQLSERVER\Store\fDirectory\test.xlsx
That is required by design. Please refer to
https://connect.microsoft.com/SQLServer/feedback/details/729273/sql-server-denali-filetable-access-using-sqlfilestream-returns-error-the-mounted-file-system-does-not-support-extended-attributes
and
Access FILESTREAM Data with OpenSqlFilestream
http://technet.microsoft.com/en-us/library/bb933972.aspx
I've a SQL Server 2005 database backup named backupdb.bak.I want to restore it to database MyDatabase.
But before restoring I've to check whether MyDatabase already exists or not. If it does then I create a new database named MyDatabaseNew and I restore the backup file to this new database.
If I'm directly restoring the file into MyDatabase, the process is running fine. But when I'm checking the existence of MyDatabase and trying to create new database named MyDatabaseNew, it's giving error:
Restore failed for Server servername
My code looks like this:
Restore restore = new Restore();
restore.Action = RestoreActionType.Database;
CreateDatabase(MyDatabaseNew);
restore.Database = MyDatabaseNew;
restore.ReplaceDatabase = true;
BackupDeviceItem deviceItem = new BackupDeviceItem("C:\\backupdb.bak",DeviceType.File);
restore.Devices.Add(deviceItem);
SqlConnection sqlCon = new SqlConnection("Data Source=.;Initial Catalog=MyDatabaseNewIntegrated Security=True;User ID=uid; Pwd=Pwd");
ServerConnection connection = new ServerConnection(sqlCon);
sqlCon.Open();
Microsoft.SqlServer.Management.Smo.Server smoServer = new Server(new ServerConnection("."));
if (File.Exists("C:\\backupdb.bak"))
// restore
restore.SqlRestore(smoServer);
if (sqlCon.State == ConnectionState.Open)
sqlCon.Close();
and my create database (in case MyDatabase exists) code looks like this, where I'm passing MyDatabaseNew as a parameter for this method:
public void CreateDatabase(string NewDBName)
{
string str;
SqlConnection myConn = new SqlConnection("Server=.;Integrated security=True;
database=master;User ID=uid;Password=Pwd");
str = "CREATE DATABASE " + NewDBName + "";
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
MessageBox.Show("New DataBase is Created Successfully", "Database Creation",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "Database Creation", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
}
}
}
Can any one tell me where I'm going wrong?
When restoring to the new database, you need to use an equivalent of Transact-SQL's RESTORE DATABASE ... WITH MOVE ... statement to specify new names for the data and log files:
restore.RelocateFiles.Add(new RelocateFile("MyDatabase", #"c:\MyDatabaseNew.mdf"));
restore.RelocateFiles.Add(new RelocateFile("MyDatabase_Log", #"c:\MyDatabaseNew.ldf"));
More information: Getting Started with SMO in SQL 2005 - Restores
I am trying to connect to mysql database from a .NET compact framework using C#. Each time I run the program, I get a missingmanifestresourceexception just at the point of opening the connection.
Can any one please tell me how to go about this, I've lost four days already.
P.S: I already added the reference Mysql.Data.CF.
my code is as below
string MyConString ="SERVER=localhost;" + "DATABASE=kunle;" + "UID=root;" + "PASSWORD=olakay;"+ "pooling=false;";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select * from mycustomers";
try
{
connection.Open(); //***this is the point where I get the error***
MessageBox.Show("Connected successfully");
}
catch (MySqlException asd)
{
MessageBox.Show("" + asd.Message);
}
catch (MissingManifestResourceException ex)
{
MessageBox.Show("" + ex.Message);
}
Reader = command.ExecuteReader();
while (Reader.Read())
{
//statement goes here;
}
connection.Close();
will be looking forward to an answer from anyone.
Olakay.
Put "pooling=false" in the connection string. It resolved my problem.
Which version of connector are you using. I have succeeded with 5.2.7
I have posted resolution for this on MySql forum
http://forums.mysql.com/read.php?38,228101,276266#msg-276266