juFo juFo - 1 year ago 184
C# Question

SQLite invalid URI after updating System.Data.SQLite.dll

I first had this SQLite version: (sqlite-netFx40-static-binary-bundle-Win32-2010-
and everything was working fine.
After updating my System.Data.SQLite.dll to version (sqlite-netFx40-static-binary-bundle-Win32-2010- I now receive this:

Unable to open database. Connection string: 'datetimeformat=ISO8601;synchronous=Off;uri="file://C:/Users/username/Documents/data/test.db";version=3;journal mode=Truncate;default isolationlevel=ReadCommitted;pooling=True'; Error: 'System.InvalidOperationException: Invalid connection string: invalid URI

I've also tried file:/// instead of file:// without any luck.

Could anybody tell me what is wrong with my URI, why it doesn't work anymore in v1.0.82.0 but worked in v1.0.77.0?

( == 3.7.14)

Answer Source

The best way to get correct connection string is to always use the SQLiteConnectionStringBuilder class to generate them.

SQLiteConnectionStringBuilder conn_builder = new SQLiteConnectionStringBuilder 
   DateTimeFormat = SQLiteDateFormats.ISO8601,
   SyncMode = SynchronizationModes.Off,
   Version = 3,
   JournalMode = SQLiteJournalModeEnum.Truncate,
   DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted,
   Pooling = true,
   Uri = new Uri(@"c:\tmp\db.sqlite").AbsoluteUri
 string conn_str = conn_builder.ConnectionString;

if Uri is not working, try setting DataSource instead (if you are using a local file).

A quick check shows that DataSource is evaluated before Uri in SQLiteConnection.cs and takes precedence over it, so if there is a bug in the Uri handling, using DataSource may help bypassing it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download