Adaptive 32-bit/64-bit System for. NET applications using SQLite

Source: Internet
Author: User
Tags sqlite download vc runtime

If a. NET application needs to adapt to a 32-bit/64-bit system, you only need to set it to "Any CPU" on the "Target Platform" of the project ". However, if SQLite is used in the application, the situation is different.


The. NET development kit of SQLite comes from System. Data. SQLite. It is compatible with the ADO. NET interface and also provides the implementation of Linq and Entity Framework 6. But this is not important. What is important is that System. Data. SQLite is composed of two parts of the Code, one is the non-managed C ++ code implementation, and the other is the managed code and. NET Framework interface. Because the unmanaged code cannot be constructed as an "Any CPU", every package on the System. Data. SQLite download page is differentiated by a 32-bit or 64-bit System.


By the way, the System. Data. SQLite download page is dizzy. Although it took a lot of space to explain how to choose to download the page from the very beginning, it is estimated that few will read it, so here is a brief introduction.


1) First, it is divided into installation packages, Binary packages for non-static connections, and Binary packages for static connections by type. The installation package installs the relevant dynamic libraries in the system and registers them to GACGlobal Assembly Cache). The difference between the two Binary packages is that the connection methods of the unmanaged parts are different, non-static connection Binary packages must be supported by the VC Runtime Library during use. Note: To connect to the SQLite database in Visual Studio, You must select an appropriate installation package for installation.


For example, to connect to sqlitein Visual Studio 2010, you should download “sqlite-netfx40-setup-bundle-x86-2010-1.0.90.0.exe, which has clear instructions on the downloaded package.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140209/235340M02-0.jpg "title =" 20140209_114901.png "alt =" wKioL1L2-2mij_P_AAJV6pRtu7c170.jpg "/>
[The instructions for downloading the package contain clear instructions in bold.]


After installation, you can connect to SQLite in Visual Studio 2010:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140209/2353402126-1.jpg "title =" 20140208_215300.png "alt =" wKiom1L2-eqwJv4jAAE2HS7eYKM589.jpg "/>
[Connecting to SQLite in Visual Studio]


2) each type is divided into several groups by. NET version. Currently, from. NET 2.0 SP2 to. NET 4.5.1, a total of five versions of. NET Framework are supported. Each. NET version is divided into two groups: 32-bit and 64-bit. 32-bit or 64-bit depends on the system. For example, if a 64-bit System is developed and runs on a 32-bit System after release, you need to use a 64-bit System during development. data. SQLite. dll. data. SQLite. dll replacement looks very troublesome ~~ Please refer to the Solution Below ~~).


3) Each. NET version group has two packages, one with the word "bundle" and the other. The dynamic library with the word "bundle" is compiled in hybrid mode. data. SQLite. the dll can be used, but without the "bundle", it is to compile the unmanaged part and the managed part separately, System. data. SQLite. dll cannot be used independently. SQLite is also required. interop. dll can be used.


To put it bluntly, if you want to use System. Data. SQLite. dll of "Any CPU", you must use a binary package that does not contain "bundle", that is, non-mixed compilation.


The binary package for non-mixed compilation includes two dynamic libraries: System. Data. SQLite. dll and SQLite. Interop. dll. According to official instructions, SQLite. interop. dll can be stored with System. data. SQLite. the same dll Directory can also be placed in the x86 or x64 sub-directories. data. SQLite. dll is called according to the system type. To confirm, download the following two packages for comparison:

Sqlite-netFx40-binary-Win32-2010-1.0.90.0.zip

Sqlite-netFx40-binary-x64-2010-1.0.90.0.zip

The results show that only SQLite. Interop. * is different, and all other files are identical.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140209/23534045X-2.jpg "title =" 20140208_221817.png "alt =" wKiom1L3AN-yjXWaAAdjyVYpUAk800.jpg "/>
[Comparison result: Only SQLite. Interop. * is different]


Then, the SQLite. Interop. * of the two packages are placed under the x86 and x64 sub-directories respectively, and merged into a package. Run test.exe in a different operating system, and the result is all passed.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140209/2353402553-3.jpg "title =" 20140208_222715.png "alt =" wKioL1L3AWWiY0tNAAUO5xpmciI727.jpg "/>


The last thing to do is to reference System in the Visual Studio project. data. SQLite. dll, and then x86 \ SQLite. interop. dll and x64 \ SQLite. interop. copy the dll to the project root directory and include it in the project. In the properties, set "copy if new" or "always copy ". The generated result is as follows:

TestSQLite \ bin \ Debug

│ System. Data. SQLite. dll

│ TestSQLite.exe

─ ── X64

│ SQLite. Interop. dll

─ ── X86

SQLite. Interop. dll

The package is named “sqlite-netfx40-static-binary-x86-x64-2010-1.0.90.0.zip.

◆ BKJIA Resource Site Sharing

◆ 360 cloud disk sharing

This article from the "Edge City inn xuehai Wuxi" blog, please be sure to keep this source http://jamesfancy.blog.51cto.com/2516291/1357462

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.