Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Data Source cannot be empty. Use :memory: to open an in-memory database" mean?

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.

like image 291
Verve Innovation Avatar asked Oct 28 '10 04:10

Verve Innovation


2 Answers

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).

like image 70
tomRedox Avatar answered Oct 20 '22 15:10

tomRedox


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"
like image 12
Ben Straub Avatar answered Oct 20 '22 15:10

Ben Straub