MissingManifestResourceException - compact-framework

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

Related

java.sql.SQLException: No suitable driver found for jdbc:sqlserver when connecting to azure database

im using an azure database and I added all necessary JAR files to my library. Here is my code, im not sure why it is unable to connect. Please advise.
String connectionUrl =
"jdbc:sqlserver://bcs430-final-project.database.windows.net:1433;"
+ "database=OASIS ASSISTANT;"
+ "user=farmingdale#bcs430-final-project;"
+ "password=bcs430w!;"
+ "encrypt=true;"
+ "trustServerCertificate=false;"
+ "loginTimeout=30;";
String insertSql = "select * from dbo.BCS102 where crse = bcs102 ";
ResultSet resultSet = null;
try (Connection connection = DriverManager.getConnection(connectionUrl);
PreparedStatement prepsInsertProduct = connection.prepareStatement(insertSql, Statement.RETURN_GENERATED_KEYS);) {
prepsInsertProduct.execute();
// Retrieve the generated key from the insert.
resultSet = prepsInsertProduct.getGeneratedKeys();
// Print the ID of the inserted row.
while (resultSet.next()) {
System.out.println("Generated: " + resultSet.getString(1));
}
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
here is the error
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://bcs430-final-project.database.windows.net:1433;database=OASIS ASSISTANT;user=farmingdale#bcs430-final-project;password=bcs430w!;encrypt=true;trustServerCertificate=false;loginTimeout=30;
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at SeniorProject.main(SeniorProject.java:35)
The error shows that you didn't install suitable the drive for JDBC.
Please check the if you have add the dependency. Add the Microsoft JDBC Driver for SQL Server to your project's dependencies using the following code.
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>
For more details, you can reference this document Quickstart: Use Java to connect to and query an Azure SQL database.You can follow this tutorial and avoid the error.
In addition, you want to connect to your Azure SQL database with AD authentication, you connection string should like this:
jdbc:sqlserver://***.database.windows.net:1433;database=Mydatabase;user={your_username_here};password={your_password_here};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;authentication=ActiveDirectoryPassword
You can get the AD connection string on Portal:
Hope this helps.

How to use SqlFileStream for transactional access to SQL Server 2012 FileTable?

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

Accessing UniData through .net

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.

How to restore SQL Server database backup to a newly created database?

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

How do I programmatically tell if a client machine has the Microsoft.Jet.OLEDB.4.0 as a valid provider?

I need to export data into an Access database. My code works, but it works with the assumption the client machine has the Microsoft.Jet.OLEDB.4.0 as a valid provider.
I want to test to see if this is true or not, in code. My problem is that I don't have the location of an existing access database and I don't want to create a new .mdb that I'd use to verify the connection and then delete it.
Is there any way to tell which providers are installed?
You could simply check for the existence of
HKEY_CLASSES_ROOT\CLSID\{dee35070-506b-11cf-b1aa-00aa00b8de95}
which is the CLSID of Microsoft.Jet.OLEDB.4.0.
you could try to detect the MDAC version on the machine and based on that extrapolate if your provider is supported?
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=47262&lngWId=1
here's a snippet you can take a look at.
Each major provider has classid mentioned under the registry editor
Ex:-
HKEY_CLASSES_ROOT\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}
which is the CLSID of Microsoft.Jet.OLEDB.4.0.
To check programmatically, use below c# code, its checked on framework 2.0
using System.Data.OleDb;
OleDbEnumerator enumerator = new OleDbEnumerator();
DataTable table = enumerator.GetElements();
bool bNameFound = false;
bool bCLSIDFound = false;
foreach (DataRow row in table.Rows)
{
foreach (DataColumn col in table.Columns)
{
if ((col.ColumnName.Contains("SOURCES_CLSID")) && (row[col].ToString().Contains("{dee35070-506b-11cf-b1aa-00aa00b8de95}")))
Console.WriteLine("CLSID of Microsoft.Jet.OLEDB.4.0. Found");
if ((col.ColumnName.Contains("SOURCES_NAME")) && (row[col].ToString().Contains("Microsoft.ACE.OLEDB.12.0")))
{
bNameFound = true;
if ((col.ColumnName.Contains("SOURCES_CLSID")) && (row[col].ToString().Contains("{3BE786A0-0366-4F5C-9434-25CF162E475E}")))
bCLSIDFound = true;
}
}
}
if (!bNameFound && !bCLSIDFound)
Console.WriteLine("Microsoft.ACE.OLEDB.12.0 Not found");
else
Console.WriteLine("Microsoft.ACE.OLEDB.12.0 found");
Remember "Fix it right & not let the test bugs bite"
I believe if you have the .NET Framework installed (needed to run VB.NET Code) then the machine has the provider you mention. MSDN
Dim reader As Object = OleDbEnumerator.GetRootEnumerator()
Dim Oleprovide As String = ""
While reader.Read
For i = 0 To reader.FieldCount - 1
If reader.GetName(i) = "SOURCES_NAME" Then
If reader.GetValue(i).ToString.Contains(".OLEDB.") = True Then
Oleprovide = reader.GetValue(i).ToString
Exit For
End If
End If
Next
End While
reader.Close()
Dim MyConnection As OleDbConnection
MyConnection = New OleDbConnection("Provider=" & Oleprovide & ";Data Source=" & existingFile.FullName & ";Extended Properties=""Excel 13.0 Xml;HDR=Yes""")
MyConnection.Open()