C# SQlite 连接字符串格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15726265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 17:45:40  来源:igfitidea点击:

C# SQlite Connection String Format

c#.netdatabasesqlite

提问by Kairan

I have a 2 part question here

我在这里有一个两部分的问题

1) I downloaded SQLite from here: SQLite Websiteand for .NET 4.5 there was a "mixed" mode version and the "non-mixed mode" version. How do I know which one I should use?

1)我从这里下载了 SQLite:SQLite 网站,对于 .NET 4.5,有一个“混合”模式版本和“非混合模式”版本。我怎么知道我应该使用哪一种?

When making a connection I use the following command:

建立连接时,我使用以下命令:

sqlite_conn = new SQLiteConnection("Data Source=db.db;Version=3;New=True;Compress=True;");

sqlite_conn = new SQLiteConnection("Data Source=db.db;Version=3;New=True;Compress=True;");

2) The "Version=3" I assume represents the version of SQLite being used. So if I download from the link above the version says System.Data.SQLite 1.0.84.0 (3.7.15.2) package so should I be changing the Version=3 to Version=3.7.15.2 ??

2)我假设的“Version = 3”代表正在使用的SQLite版本。因此,如果我从上面的链接下载版本为 System.Data.SQLite 1.0.84.0 (3.7.15.2) 包,那么我应该将 Version=3 更改为 Version=3.7.15.2 吗??

采纳答案by Max

  1. You should pick the Mixed one.
  2. the 1.0.84.0 is the newest version out for the SQLite DLL. I created an application with SQLitetoo in c#, my connection stringlooks like the following:

    sqlite_conn = new SQLiteConnection("Data Source=C:\SQLITEDATABASES\SQLITEDB1.sqlite;Version=3;");
    
  1. 你应该选择混合的。
  2. 1.0.84.0 是SQLite DLL. 我用SQLitetoo in创建了一个应用程序c#,我的连接字符串如下所示:

    sqlite_conn = new SQLiteConnection("Data Source=C:\SQLITEDATABASES\SQLITEDB1.sqlite;Version=3;");
    

The version you are using, is SQLiteversion 3, the DLL is just a different version, but works with SQLiteversion 3.

您使用的版本是SQLite版本 3,DLL 只是一个不同的版本,但适用于SQLite版本 3。

回答by VictorEE

SQLite is written in C. For Windows, it is distributed as a compiled 32 bit (x86) .dll. This cannot be used from .NET directly because it is native code and .NET programs don't normally like to interact with native code. It can be done with something called COM Interop, but in my hands that is not easy or pretty.

SQLite 是用 C 编写的。对于 Windows,它作为编译的 32 位 (x86) .dll 分发。这不能直接从 .NET 使用,因为它是本机代码,而 .NET 程序通常不喜欢与本机代码交互。它可以通过称为 COM Interop 的东西来完成,但在我手中这并不容易或漂亮。

In your question you reference a download page that is for System.Data.SQLite. This is a slightly different implementation than plain old SQLite. It takes C SQLite and wraps it with .NET code - allowing use of the C native code by .NET programs (hooray, someone else did the work).

在您的问题中,您引用了 System.Data.SQLite 的下载页面。这与普通的旧 SQLite 实现略有不同。它采用 C SQLite 并用 .NET 代码包装它 - 允许 .NET 程序使用 C 本机代码(万岁,其他人完成了这项工作)。

When you have both native code (the C SQLite) and .NET code (the wrapper functions) together in one assembly, that is called a mixed-mode assembly, and originally it made sense to put everything in one file. If you are doing development or only using SQLite on your own machine, then using a mixed-mode assembly is fine.

当您在一个程序集中同时拥有本机代码(C SQLite)和 .NET 代码(包装函数)时,这称为混合模式程序集,最初将所有内容放在一个文件中是有意义的。如果您正在进行开发或仅在您自己的机器上使用 SQLite,那么使用混合模式程序集就可以了。

However, things have changed with 64 bit Windows IF you want to distribute your application to customers. This is because mixed-mode assemblies can only run on the architecture they were compiled for (a white lie, but true for this answer). As of version 1.0.80.0 of System.Data.SQLite, it is strongly suggested you distribute: 1.) The all .NET .dll System.Data.SQLite.dll, which can run on 32 bit or 64 bit architectures) AND 2.) a 32-bit .dll x86\SQLite.Interop.dll AND 3. a 64 bit .dll x64\SQLite.Interop.dll

但是,如果您想将应用程序分发给客户,那么 64 位 Windows 的情况就发生了变化。这是因为混合模式程序集只能在它们编译的体系结构上运行(善意的谎言,但对于这个答案是正确的)。从 System.Data.SQLite 1.0.80.0 版本开始,强烈建议您分发:1.) 全 .NET .dll System.Data.SQLite.dll,可以在 32 位或 64 位体系结构上运行)和 2 .) 32 位 .dll x86\SQLite.Interop.dll 和 3. 64 位 .dll x64\SQLite.Interop.dll

The all .NET wrapper (item 1) figures out which which architecture it is running on and picks the 32 bit or 64 bit .dll accordingly.

全 .NET 包装器(第 1 项)确定它在哪个体系结构上运行,并相应地选择 32 位或 64 位 .dll。

All this is described on the System.Data.SQLite downloads page that you referenced, but I found it confusing so I offer my summary.

所有这些都在您引用的 System.Data.SQLite 下载页面上进行了描述,但我发现它令人困惑,所以我提供了我的摘要。

The version discrepancy you note in your question is also due to the difference between SQLite and System.Data.SQLite.

您在问题中注意到的版本差异也是由于 SQLite 和 System.Data.SQLite 之间的差异。

回答by Ramgy Borja

The following are different type of Sqlite Connection String

以下是不同类型的 Sqlite 连接字符串

Basic

基本的

Data Source=c:\mydb.db;Version=3;

Data Source=c:\mydb.db;Version=3;

Version 2 is not supported by this class library.

此类库不支持版本 2。

In-Memory DatabaseAn SQLite database is normally stored on disk but the database can also be stored in memory.

内存数据库SQLite 数据库通常存储在磁盘上,但数据库也可以存储在内存中。

Data Source=:memory:;Version=3;New=True;

Data Source=:memory:;Version=3;New=True;

Using UTF16

使用 UTF16

Data Source=c:\mydb.db;Version=3;UseUTF16Encoding=True;

Data Source=c:\mydb.db;Version=3;UseUTF16Encoding=True;

With password

有密码

Data Source=c:\mydb.db;Version=3;Password=myPassword;

Data Source=c:\mydb.db;Version=3;Password=myPassword;