12

I recently converted my SQL Server database into SQLite DB. But when I try to open my SQLite using .Open() it throws me this error:

Data Source cannot be empty.  Use :memory: to open an in-memory database

Edit: added connection string:

ConnectionString = @"Data Source=D:\XXX.db;Version=3";
connection = new SQLiteConnection(connectionString);
connection.Open();

Why do I get this? I converted the same SQL Server database to SQL CE and mySQL and I didn't get these errors.

4
  • 1
    please put the connection string in the question. Commented Oct 28, 2010 at 4:21
  • ConnectionString = @"Data Source= D:\XXX.db;Version=3;connection = new SQLiteConnection(connectionString); connection.Open(); Commented Oct 28, 2010 at 4:29
  • Is that space significant after the = ?? Data Source= D:\XXX.db Commented Oct 28, 2010 at 4:40
  • sorry guys its my mistake .. at one place i have mentioned as"datasource" without spaces ..that caused the problem. Thanks Commented Oct 28, 2010 at 4:44

4 Answers 4

13

There's a space after your data source: Data Source= D:\XXX.db. Also, in your copy/paste, there's no closing quote to the connection string. Here's a connection string that works for me for the testing tool:

@"Data Source=C:\Temp\Test.db3;Pooling=true;FailIfMissing=false;Version=3"
1
  • Thanks dude. I already figured that out and you can see that in my comment below the question Commented Nov 13, 2011 at 21:28
3

I had this same error recently when I actually was trying to use the in memory version of SQLite.

I was setting up the connection as follows:

var connection = new SQLiteConnection("Filename=:memory:");
connection.Open();

And getting the error

Data Source cannot be empty. Use :memory: to open an in-memory

I then changed it to this code, note the 'SQL' part is no longer capitalised:

var connection = new SqliteConnection("Filename=:memory:");
connection.Open();

And now it works.

The working, non capitalised version is from the Microsoft.Data.Sqlite.SqliteConnection namespace where as the SQLite version is from System.Data.SQLite.SQLiteConnection (I had version 1.0.113.6 referenced).

1

You haven't provided a data source name, aka where the sqlite file exists.

1
  • I did ,refer my other comments Commented Oct 28, 2010 at 4:30
0

Because your Data Source is empty. Add the Data Source paramater to your connection string. before opening the Sqlite database.

3
  • Its not empty .I had specified exact path dude.. connectionString = @"Data Source= D:\XXX.db;Version=3; connection = new SQLiteConnection(connectionString); connection.Open(); Commented Oct 28, 2010 at 4:28
  • Perhaps removing the space from the front of the `D:` and close the connectionString with a double quote might help.
    – tidwall
    Commented Oct 28, 2010 at 4:45
  • sorry guys its my mistake .. at one place i have mentioned as"datasource" without spaces ..that caused the problem. Thanks Commented Oct 28, 2010 at 5:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.