I try to work with a SQL Server CE 4.0 database with my simple console app but it is not working on one of my machine.
OS: Windows Server 2003 Enterprise x64 Edition with Service Pack 2
I have also installed Microsoft SQL Server Compact 4.0 and used its dll (System.Data.SqlServerCe.dll
) but every time I got following error
Unable to load the native components of SQL Server C ADO.NET provider of version 8080. Install the correc act. Refer to KB article 974247 for more details.
Here is my code
try
{
Console.WriteLine("Started");
var sqlConnectionString = "Data Source=c:\\tde\\22\\22.tde;password='sanjayraj';mode=Read Write;max database size=4091;temp file max size=4091";
_connection = new SqlCeConnection(sqlConnectionString);
_connection.Open();
var sqlStatement = "SELECT * FROM InfoStores WHERE Location = 'Source'";
IDbCommand newCommand = new SqlCeCommand
{
CommandText = sqlStatement,
Connection = _connection,
CommandType = CommandType.Text
};
using (IDataReader reader = newCommand.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error Occured");
Console.WriteLine(ex.Message);
Console.ReadKey();
}
Console.WriteLine("Finished");
Console.ReadKey();