How does the SQLite Entity Framework 6 provider handle Guids?

It appears that this was resolved in 1.0.95 however broken again in 1.0.97. The solution is to set the BinaryGUID property on the connection string to true and set the following environment variable (before you make the connection) Environment.SetEnvironmentVariable(“AppendManifestToken_SQLiteProviderManifest”,”;BinaryGUID=True;”); Data Source=c:\mydb.db;Version=3;BinaryGUID=True; https://www.connectionstrings.com/sqlite/

SQLite keeps the database locked even after the connection is closed

I had the same problem using the datasets/tableadapters generated with the designer shipped with System.Data.Sqlite.dll version 1.0.82.0 — after closing the connection we were unable to read the database file using System.IO.FileStream. I was disposing correctly both connection and tableadapters and I was not using connection pooling. According to my first searches (for example this … Read more

Create/Use User-defined functions in System.Data.SQLite?

Robert Simpson has a great example of a REGEX function you can use in your sqlite queries: // taken from http://sqlite.phxsoftware.com/forums/p/348/1457.aspx#1457 [SQLiteFunction(Name = “REGEXP”, Arguments = 2, FuncType = FunctionType.Scalar)] class MyRegEx : SQLiteFunction { public override object Invoke(object[] args) { return System.Text.RegularExpressions.Regex.IsMatch(Convert.ToString(args[1]),Convert.ToString(args[0])); } } // example SQL: SELECT * FROM Foo WHERE Foo.Name REGEXP … Read more

SQLite Insert very slow?

Wrap BEGIN \ END statements around your bulk inserts. Sqlite is optimized for transactions. dbcon = new SQLiteConnection(connectionString); dbcon.Open(); SQLiteCommand sqlComm; sqlComm = new SQLiteCommand(“begin”, dbcon); sqlComm.ExecuteNonQuery(); //—INSIDE LOOP sqlComm = new SQLiteCommand(sqlQuery, dbcon); nRowUpdatedCount = sqlComm.ExecuteNonQuery(); //—END LOOP sqlComm = new SQLiteCommand(“end”, dbcon); sqlComm.ExecuteNonQuery(); dbcon.close();

Adding parameters in SQLite with C#

Try a different approach, naming your fields in the query and naming the parameters in the query: this.command.CommandText = “INSERT INTO StringData (field1, field2) VALUES(@param1, @param2)”; this.command.CommandType = CommandType.Text; this.command.Parameters.Add(new SQLiteParameter(“@param1”, data.Data)); this.command.Parameters.Add(new SQLiteParameter(“@param2”, data.ByteIndex)); …

SQLite Database Locked exception

Somewhere along the way a connection is getting left open. Get rid of OpenConnection and CloseConnection and change ExecuteNonQuery to this: using (SQLiteConnection c = new SQLiteConnection(ConnectionString)) { c.Open(); using (SQLiteCommand cmd = new SQLiteCommand(sql, c)) { cmd.ExecuteNonQuery(); } } Further, change the way you read data to this: using (SQLiteConnection c = new SQLiteConnection(ConnectionString)) … Read more

What ‘additional configuration’ is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?

In order to use a CLR 2.0 mixed mode assembly, you need to modify your App.Config file to include: <?xml version=”1.0″?><configuration> <startup useLegacyV2RuntimeActivationPolicy=”true”> <supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.0″/> </startup></configuration> The key is the useLegacyV2RuntimeActivationPolicy flag. This causes the CLR to use the latest version (4.0) to load your mixed mode assembly. Without this, it will not work. … Read more