【问题标题】:Published Winform Issue已发布 Winform 问题
【发布时间】: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 用于该目录的内容。您不能保证目录路径上不会有尾随“\”,从而使您的结果无效。

标签: c# winforms


【解决方案1】:

我在下载了 SQlite.Interop.dll x86 和 x64 here 后修复了这个问题。然后 在我的项目中创建了 x86 和 x64 文件夹,并将 dll 相应地放入文件夹中。然后编辑项目属性并取消选中首选32位

【讨论】:

    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 2012-05-12
    • 1970-01-01
    相关资源
    最近更新 更多