vb.net - 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,但这并不能解决问题。
解决方案
推荐阅读
- r - R:如何在应用互相关之前格式化数据
- amazon-web-services - 无法通过 API Gateway 使用 POST 方法发送 JSON 数据
- javascript - 扩展或包装canvas.getContext()接收到的对象
- tuples - 在 CPLEX 中定义元组
- windows - 批处理脚本 - 使用管道时未设置环境变量
- javascript - 中心弹出固定对齐仅适用于移动视图
- javascript - 我可以做1个以上的ID吗?
- python - 如何在子工厂(Django)中包含多对多字段?
- c - 在 C 中使用递归计算二项式系数
- python - 带有 seaborn joinplot 的 2D 核密度图