S
S
StrangeAttractor2015-01-15 22:18:59
.NET
StrangeAttractor, 2015-01-15 22:18:59

How to make an application using SQLite WinForms.Net work on both 32 and 64 bit systems?

As far as I understand, the System.Data.SQLite libraries require undmanaged SQLite libraries for their work, which are available for 64 and 32-bit versions of Windows. How to make such an application that will connect the appropriate version depending on which machine it is running on?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AxisPod, 2015-01-16
@AxisPod

I did it in 2 ways, I can’t describe one now, it’s too cumbersome (and it doesn’t allow you to change it in runtime, you still have to build 2 versions of the application).
Here is a simpler option stackoverflow.com/questions/11934570/change-c-shar... You
need to put the x86 and x64 libraries in the appropriate folders, and put the code in the Main method as indicated there.
Although in principle you can try using MEF here, you will need .NET 4.5 at least here.

T
tsul, 2015-02-17
@tsul

This can be done using the built-in feature of System.Data.SQLite, which looks for the version of SQLite.Interop.dll, not only next to itself, but also in the directory, resp. architecture, i.e. x86 or x64 respectively.
See Using Native Library Pre-Loading on their wiki .
Did it like this:

  • In the project, I made Private Reference (i.e. Copy Local = True) to System.Data.SQLite.dll, and links with paths to Interop dlls. The links in csproj look like this (it seems that the rules are hand-made so that the paths are x86 and x64):
    <Content Include="..\..\..\cs\Common\SQLite\x86\SQLite.Interop.dll">
          <Link>x86\SQLite.Interop.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <Content Include="..\..\..\cs\Common\SQLite\x86\SQLite.Interop.pdb">
          <Link>x86\SQLite.Interop.pdb</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <Content Include="..\..\..\cs\Common\SQLite\x64\SQLite.Interop.dll">
          <Link>x64\SQLite.Interop.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <Content Include="..\..\..\cs\Common\SQLite\x64\SQLite.Interop.pdb">
          <Link>x64\SQLite.Interop.pdb</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>

  • Everything, after assembly in Debug or Release, two directories x86 and x64 are obtained, respectively. SQLite.Interop.dll, System.Data.SQLite.dll and the exe-file of the program, which works in Windows of any bitness.
    It was even a little more complicated there, because I had the same project under Mono on Linux, so there were still links to libsqlite3.so.0, but that's another story.

    Didn't find what you were looking for?

    Ask your question

    Ask a Question

    731 491 924 answers to any question