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

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

问题描述

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

  System.BadImageFormatException:
无法加载文件或程序集'System.Data.SQLite,Version = 1.0.65.0,Culture = neutral,
PublicKeyToken = db937bc2d44ff139'或一个的依赖。尝试加载格式不正确的程序。
文件名:'System.Data.SQLite,
版本= 1.0.65.0,
文化=中立,
PublicKeyToken = db937bc2d44ff139'

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


  1. 添加一些指令,如 #IFDEF (x86包含部分代码)或x64代码

  2. 加入dll只能生成一个。

  3. 在VB.net中引用此DLL

你认为是其他更好的想法,因为我想只有一个编译,而不是一个x32和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

私有共享子CloseConection(ByRef Conn As SQLite.SQLiteConnection)
康涅狄格关闭()
Conn.Dispose()
Conn = Nothing
End Sub

公共共享函数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
如果DataTAbleName不是,那么返回新的DataTable(DataTAbleName)
尝试
OpenConection(conexion)
lTA =新的SQLite.SQLiteDataAdapter(SELECT& sQuery& FROM& DataTAbleName& IIf(sWhere<> String.Empty,WHERE,)& sbhere b $ b lTA.Fill(lDT)
Catch ex As Exception
抛出ex
最后
CloseConection(conexion)
lTA.Dispose()
lTA =没有
结束尝试
返回lDT
结束函数

如何更改在64位架构上工作?
可能包括32和64 dll的,并且在函数中执行类似

 尝试
Instance = Me
'检查如果Homidom以32位或64位运行
如果IntPtr.Size = 8则_OsPlatForm =64否则_OsPlatForm =32
'继续代码

Catch ex As Exception
'ex.Message
End尝试


解决方案

从.NET程序集中使用SQLite有各种各样的选项。你的第一步是移动到比旧的1.0.65版本更新的东西。当前版本可以从这里下载: http://系统.data.sqlite.org / index.html / doc / trunk / www / downloads.wiki 或通过 SQLite NuGet软件包



如果您需要能够在32位和64位下运行,一个选项是使用本地库预加载选项,您可以将本机二进制文件分发到单独的目录中,使其如下所示:




  • \App.exe(可选的,仅管理应用程序可执行程序集)

  • \App.dll(可选的,仅受管理的应用程序库程序集)

  • \System.Data.SQLite.dll(必需,仅管理核心程序集)

  • \System.Data.SQLite.Linq.dll(可选,管理 - 只有LINQ程序集)

  • \x86\SQLite.Interop.dll(必需的,x86 native intero p程序集)

  • \x64\SQLite.Interop.dll(必需,x64本机interop程序集)



另一个选项是构建您的应用程序的两个版本,并在每个版本中引用相应的混合模式程序集。然后你会得到两个版本,但是它们有点简单,因为你不需要额外的子目录和本机* .Interop.dll。



<在这些情况下,您不需要32位和64位之间的代码差异或可选编译。从不同的NuGet软件包安装可能会让您最容易地开始使用。



最后一个选项是去C#-SQLite的受管理的克隆: https://code.google.com/p/csharp-sqlite/ 。它是一个管理C#的SQLite引擎的端口,所以整个事情都是以AnyCPU运行的,而且这一点不是一个问题。


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'

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

  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

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

For instance (32 bits):

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

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

解决方案

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.

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 (optional, managed-only application executable assembly)
  • \App.dll (optional, managed-only application library assembly)
  • \System.Data.SQLite.dll (required, managed-only core assembly)
  • \System.Data.SQLite.Linq.dll (optional, managed-only LINQ assembly)
  • \x86\SQLite.Interop.dll (required, x86 native interop assembly)
  • \x64\SQLite.Interop.dll (required, x64 native interop assembly)

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.

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.

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.

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

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