这是我为数据库连接编写的代码:
private static void OnTimedEvent(Object source, ElapsedEventArgs e)
{
using (SQLiteConnection con = new SQLiteConnection(connectionString))
{
try
{
con.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (con.State == System.Data.ConnectionState.Open)
{
Console.WriteLine("Database Opened");
ushort[] writeData = new ushort[10];
writeData = parseList(byteList);
if (writeData != errorBytes)
{
writeToDb(con, writeData);
}
else
{
Console.WriteLine("Error Bytes returned! BROKEN DATA!!!");
}
//con.Close();
}
else
{
Console.WriteLine("Can't open the database!");
}
}
}`
当我在编写代码的计算机上运行程序时,它正常工作并打开数据库。但是,当我在另一台计算机上运行我的程序时,代码不会进入using
语句并且找不到异常SQLite.Interop.dll
。我将System.Data.SQLite.dll
添加到了我的项目参考中。另外我在另一台计算机上有这个dll文件。我是否需要向其他计算机添加任何内容才能使该程序正常工作?
答案 0 :(得分:1)
我发现问题出在SQLite dll上。当我从NuGet包管理器安装System.Data.SQLite库并将平台目标设置为x86问题已解决。虽然在我问这个问题之前平台目标是x86但是从NuGet Package Manager重新安装库解决了我的问题。在此之前,我使用从http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki下载的dll作为我项目的参考。
答案 1 :(得分:-1)
尝试检查connectionString,SQLite文件的位置,..也许您正试图在不允许您的程序在另一台计算机上写入的地方创建它。如果存在差异,请尝试以管理员身份运行您的应用。我唯一想到的是它在创建连接时崩溃,因此它不会进入using语句。