首页 > 解决方案 > SQLite 在开发期间运行,而不是在编译后运行

问题描述

我正在编写一个用于管理 Neo4j 项目的后端文件的小应用程序。该应用程序是一个 VB.NET Windows 窗体项目。它使用 SQLite 数据库。数据库连接和读取、更新和插入功能在开发过程中在 Visual Studio 中工作。但是,当它被编译为 *.msi 或 CDROM 时,如果在尝试数据库访问时出现错误就会崩溃,

无法加载 DLL 'SQLite.Interop.dll'

我不确定为什么这需要互操作。但也许是因为我没有正确引用我的数据库进行编译。数据库位于发布文件夹中。

我使用 NUGet 导入了包括 SQLite 3.13.0 在内的引用。

在 VS 中工作的代码是(Q 是查询):

Public Class DataLib
    Public Shared SQLiteConn As SQLiteConnection
    Public Shared SQLitecnStr As String = ""
    Public Shared SQLitecmd As SQLiteCommand
    Public Shared myAdapter As SQLiteDataAdapter

     Public Shared Sub OpenConnection(Q As String)
            If SQLiteConn Is Nothing Then
                SQLitecnStr = "Data Source=" & My.Application.Info.DirectoryPath & "\db\gfg.sqlite3"
                Dim SQLiteConn As New SQLiteConnection
                SQLiteConn.ConnectionString = SQLitecnStr
                SQLitecmd = New SQLiteCommand(Q, SQLiteConn)
                SQLiteConn.Open()
                myAdapter = New SQLiteDataAdapter(SQLitecmd)
            Else
                If SQLiteConn.State = ConnectionState.Open Then
                    'do nothing
                Else
                    SQLitecnStr = "Data Source=" & My.Application.Info.DirectoryPath & "\db\gfg.sqlite3"
                    Dim SQLiteConn As New SQLiteConnection
                    SQLiteConn.ConnectionString = SQLitecnStr
                    SQLitecmd = New SQLiteCommand(Q, SQLiteConn)
                    SQLiteConn.Open()
                End If
    
            End If
        End Sub

NUGet 上的 SQLLite.Interop 适用于 VS .NET Framework 的早期版本。我正在使用 v 4.7.2。我尝试从 NUGet 添加 SQLite Core,但这并不能解决问题。

标签: vb.netsqliteinterop

解决方案


推荐阅读