用于 x86/x64 架构的 SQLite dll [英] SQLite dll for x86/x64 architectures

查看:36
本文介绍了用于 x86/x64 架构的 SQLite dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 VB.net 中开发一个程序,并使用 System.Data.SQLite 用于 .NET 的预编译二进制文件,但是它不适用于 x64 架构,而且我遇到了经典的文化问题并且没有加载正确的文件.

I am developing a program in VB.net, and using System.Data.SQLite Precompiled Binaries for .NET, However It is not working for x64 Architectures, and I am getting the classic culture problem and not loading correct file.

System.BadImageFormatException: 
Could not load file or assembly 'System.Data.SQLite, Version=1.0.65.0, Culture=neutral,
 PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'System.Data.SQLite,
 Version=1.0.65.0,
 Culture=neutral, 
 PublicKeyToken=db937bc2d44ff139'

有没有办法只使用一个dll,也许:

Is there a way to use only one dll, maybe:

  1. 添加一些指令,例如 #IFDEF(x86 包含部分代码)或其他 x64 代码
  2. 加入 dll 只生成一个.
  3. 在 VB.net 中引用这个 dll
  1. Add some directives like #IFDEF (x86 include some part of code) or else x64 code
  2. Join dlls to make only one.
  3. Reference this dll in VB.net

你认为还有其他更好的想法吗,因为我只想做一个编译,而不是一个用于 x32,另一个用于 x64.

Do you think is other better Idea, as I would like to make only one compilation, not one for x32 and other for x64.

例如(32 位):

Private Shared Sub OpenConection(ByRef Conn As SQLite.SQLiteConnection)
    Conn = New SQLite.SQLiteConnection("Data Source=" & System.Environment.CurrentDirectory & "database.db")
    Conn.Open()
End Sub

Private Shared Sub CloseConection(ByRef Conn As SQLite.SQLiteConnection)
    Conn.Close()
    Conn.Dispose()
    Conn = Nothing
End Sub

Public Shared Function ReturnSelect(ByVal DataTAbleName As String, ByVal sQuery As String, ByVal sWhere As String) As Data.DataTable
    Dim lDT As New DataTable
    Dim lTA As New SQLite.SQLiteDataAdapter
    If DataTAbleName Is Nothing Then Return New DataTable(DataTAbleName)
    Try
        OpenConection(conexion)
        lTA = New SQLite.SQLiteDataAdapter("SELECT " & sQuery & " FROM  " & DataTAbleName & IIf(sWhere <> String.Empty, " WHERE ", "") & sWhere, conexion)
        lTA.Fill(lDT)
    Catch ex As Exception
        Throw ex
    Finally
        CloseConection(conexion)
        lTA.Dispose()
        lTA = Nothing
    End Try
    Return lDT
End Function

如何更改它以在 64 位架构上工作?也许同时包含 32 和 64 dll 并且在函数中做类似的事情

How to change that to work on 64 bit architecture? Maybe including both 32 and 64 dll's and in functions do something like

Try
    Instance = Me
    'Check If Homidom Run in 32 or 64 bits
    If IntPtr.Size = 8 Then _OsPlatForm = "64" Else _OsPlatForm = "32"
    'continue code

Catch ex As Exception
    ' ex.Message
End Try

推荐答案

从 .NET 程序集使用 SQLite 有多种选择.您的第一步是迁移到比古老的 1.0.65 版本更新的版本.当前版本可以从这里下载:http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki 或通过 SQLite NuGet 包.

There are various options for using SQLite from a .NET assembly. Your first step is to move to something newer than the ancient 1.0.65 version. Current versions can be downloaded from here: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki or via the SQLite NuGet packages.

如果您需要能够在 32 位和 64 位下运行,一种选择是使用本机库预加载选项,您可以在单独的目录中分发本机二进制文件,所以它看起来像这样:

If you need to be able to run under both 32-bit and 64-bit, one option is to use the native library pre-loading option, where you distribute the native binaries in separate directories, so that it looks like this:

  • App.exe(可选的,仅限托管的应用程序可执行程序集)
  • App.dll(可选,仅限托管的应用程序库程序集)
  • System.Data.SQLite.dll(必需的,仅托管的核心程序集)
  • System.Data.SQLite.Linq.dll(可选,仅限托管的 LINQ 程序集)
  • x86SQLite.Interop.dll(必需,x86 原生互操作程序集)
  • x64SQLite.Interop.dll(必需,x64 本机互操作程序集)

另一种选择是构建两个版本的应用,并在每个版本中引用相应的混合模式程序集.然后你会得到两个版本,但它们处理起来更简单一些,因为你不需要额外的子目录和本机 *.Interop.dlls.

Another option is to build two versions of your app, and in each version you reference the appropriate mixed-mode assembly. You'd then end up with two versions, but they're a bit simpler to deal with since you don't need the extra subdirectory and native *.Interop.dlls.

在这些情况下,您不需要 32 位和 64 位之间的代码差异或可选编译.从不同的 NuGet 包安装可能会让您最容易上手.

In these cases you'd need no code differences or optional compilation between 32-bit and 64-bit. Installing from the different NuGet packages will probably get you started most easily.

最后一个选择是使用名为 C#-SQLite 的仅托管克隆:https://code.google.com/p/csharp-sqlite/.它是 SQLite 引擎到托管 C# 的端口,因此整个过程作为 AnyCPU 运行,并且位数不是问题.

A final option is to go for the managed-only clone called C#-SQLite: https://code.google.com/p/csharp-sqlite/. It's a port of the SQLite engine to managed C#, so the whole thing runs as AnyCPU and the bitness is not an issue.

这篇关于用于 x86/x64 架构的 SQLite dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆