【发布时间】:2013-10-04 05:24:56
【问题描述】:
我尝试通过我的简单控制台应用程序使用 SQL Server CE 4.0 数据库,但它在我的一台机器上无法运行。
操作系统:Windows Server 2003 Enterprise x64 Edition with Service Pack 2
我还安装了 Microsoft SQL Server Compact 4.0 并使用了它的 dll (System.Data.SqlServerCe.dll),但每次都出现以下错误
无法加载 SQL Server C 的本机组件 版本 8080 的 ADO.NET 提供程序。安装正确的 行为。有关详细信息,请参阅知识库文章 974247。
这是我的代码
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();
【问题讨论】:
标签: c# sql-server-ce-4