【发布时间】:2017-11-14 13:18:23
【问题描述】:
我有一个 winform 应用程序,它从机器的 Document 文件夹中的特定文件夹中读取 sqlite 数据库。所以基本上我正在做的是将数据从移动数据库导入到 Sql 服务器。该功能在调试时运行顺利,但在我发布应用程序、安装并运行它后,它会抛出 sqlite.interop.dll is not found。我刚刚下载了 x86 和 x64 版本的 dll 并尝试将其包含在项目中并再次发布。但错误仍然存在。
我的问题:有什么方法可以让应用程序检测到 interop.dll?
代码如下:
try
{
var directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var cn = "Data Source=" + directory + @"\Samplefolder\" + txtfilename.Text;
using (SQLiteConnection conn = new SQLiteConnection(cn))
{
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand())
{
cmd.Connection = conn;
cmd.CommandText = "SELECT * FROM Tablr";
using (SQLiteDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
// getting values from dr and assigning to a property of a class
}
}
}
}
MessageBox.Show("Successful");
}
catch(Exception message)
{
MessageBox.Show("Failed");
}
【问题讨论】:
-
有什么错误?
-
抛出对象引用未设置为对象实例
-
添加更多调试消息 - 获取更精确的错误位置..
-
看一下异常的StackTrace,这就是异常的来源。 “目录”和“txtfilename”在哪里声明?可能是“txtfilename”为空而访问“txtfilename.Text”是问题吗?
-
将
Path.Combine用于该目录的内容。您不能保证目录路径上不会有尾随“\”,从而使您的结果无效。