Sqlite“数据源不能为空”

时间:2012-06-28 12:16:52

标签: c# sqlite

我收到错误“数据源不能为空。使用:内存:打开内存数据库”

这是我的连接字符串:

// 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);

这是我的联系:

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

感谢您的帮助。

1 个答案:

答案 0 :(得分:6)

连接字符串错误时会出现该错误。

@"Data Source={0}"中 你必须把数据源而不是数据源

希望它有所帮助。

相关问题