Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite "Data source cannot be empty"

Tags:

c#

sqlite

I get the error "Data Source cannot be empty. Use :memory: to open an in-memory database"

Here is my connection string:

// Get Current Users App Data
            string documentsFolder = Environment.GetFolderPath
            (Environment.SpecialFolder.ApplicationData);
            string[] tempstr = documentsFolder.Split('\\');
            string tempstr1 = "";
            documentsFolder += "\\Google\\Chrome\\User Data\\Default\\History";
            if (tempstr[tempstr.Length - 1] != "Local")
            {
                for (int i = 0; i < tempstr.Length - 1; i++)
                {
                    tempstr1 += tempstr[i] + "\\";
                }
                documentsFolder = tempstr1 + "Local\\Google\\Chrome\\User Data\\Default\\History";
            }

            // Check if directory exists
            if (Directory.Exists(documentsFolder))
            {
            //    return ExtractUserHistory(documentsFolder);

            }

            string connectionString;
            connectionString = string.Format(@"DataSource={0}", documentsFolder);

And here is my connection:

    SQLiteConnection conn = new SQLiteConnection(connectionString);
    conn.Open();

Thanks for any help.

like image 910
CC Inc Avatar asked Apr 02 '26 03:04

CC Inc


1 Answers

That error is given when the connection string is wrong.

In your @"Data Source={0}" you must put Data Source instead of DataSource

Hope it helps.

like image 75
Ignacio Gómez Avatar answered Apr 03 '26 17:04

Ignacio Gómez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!