在 .net 中将 sqlite pragma 编码设置为 "UTF-16"

Set sqlite pragma encoding to "UTF-16" in .net

我想将 SQLite 的编码设置为 UTF-16。我怎样才能从代码中做到这一点? 最好在 vb.net 中,但我能够将 c# 转换为 vb.net

我使用这个 url 中的数据库助手 class,我将其转换为 vb.net 代码: http://tech.just4sharing.com/Pages/ASP/How-to-use-SQLite-database-in-Visual-Studio.aspx

我试过这个 vb.net 代码:

      dbConnection = "Data Source=database.s3db;PRAGMA encoding = ""UTF-16"";"

但这确实奏效了。
在@Dai post 之后,我在 SQLiteDatabase 助手 class 的构造函数中尝试了这个并删除了旧数据库

vb.net代码:

    dbConnection = "Data Source=database.s3db;"
    Dim cnn As New SQLite.SQLiteConnection(dbConnection)
    cnn.Open()
    Using cmd As SQLiteCommand = cnn.CreateCommand()
        cmd.CommandText = "PRAGMA encoding = ""UTF-16"";"
        cmd.ExecuteNonQuery()
    End Using
    cnn.Close()

c#代码:

SQLiteConnection c = new SQLiteConnection(dbConnectioN)
c.Open()
using(SQLiteCommand cmd = c.CreateCommand()) {
cmd.CommandText = "PRAGMA encoding = \"UTF-16\"";
cmd.ExecuteNonQuery();
}
c.Close()

但这也起作用了,管理员(SQLite 的 IDE)仍然很难过它是在 UTF-8 上

SQLite PRAGMA 语句被评估为 SQL 命令,因此不是连接字符串的一部分。这记录在他们的网站上:

https://www.sqlite.org/pragma.html

The PRAGMA statement is an SQL extension specific to SQLite and used to modify the operation of the SQLite library or to query the SQLite library for internal (non-table) data. The PRAGMA statement is issued using the same interface as other SQLite commands (e.g. SELECT, INSERT)

(强调我的)

所以要设置编码:

using(SQLiteCommand cmd = c.CreateCommand()) {
    cmd.CommandText = "PRAGMA encoding = \"UTF-16\"";
    cmd.ExecuteNonQuery();
}