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

后端 未结 4 2017
野趣味
野趣味 2021-01-17 12:15

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          


        
相关标签:
4条回答
  • 2021-01-17 12:31

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

    0 讨论(0)
  • 2021-01-17 12:32

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

    0 讨论(0)
  • 2021-01-17 12:33

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

    0 讨论(0)
  • 2021-01-17 12:54

    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"
    
    0 讨论(0)
提交回复
热议问题