i want to set the encoding of SQLite to UTF-16. how can i do that from code? prefferably in vb.net, but i am able to convert c# to vb.net
i use the database helper class from this url that i converted to vb.net code: http://tech.just4sharing.com/Pages/ASP/How-to-use-SQLite-database-in-Visual-Studio.aspx
i tried this vb.net code:
dbConnection = "Data Source=database.s3db;PRAGMA encoding = ""UTF-16"";"
but this diddent work.
after @Dai post i tried this in the constructor of the SQLiteDatabase helper class and deleted the old database
vb.net code:
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# code:
SQLiteConnection c = new SQLiteConnection(dbConnectioN)
c.Open()
using(SQLiteCommand cmd = c.CreateCommand()) {
cmd.CommandText = "PRAGMA encoding = \"UTF-16\"";
cmd.ExecuteNonQuery();
}
c.Close()
but this diddent work also, Administrator (The IDE of SQLite) still sad it was on UTF-8
SQLite PRAGMA statements are evaluated as SQL commands, so not part of the connection string. This is documented on their website:
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)
(emphasis mine)
So to set the encoding:
using(SQLiteCommand cmd = c.CreateCommand()) {
cmd.CommandText = "PRAGMA encoding = \"UTF-16\"";
cmd.ExecuteNonQuery();
}