C# Sqlite“;“数据源不能为空”;
我收到错误“数据源不能为空。使用:内存:打开内存中的数据库” 这是我的连接字符串:C# Sqlite“;“数据源不能为空”;,c#,sqlite,C#,Sqlite,我收到错误“数据源不能为空。使用:内存:打开内存中的数据库” 这是我的连接字符串: // Get Current Users App Data string documentsFolder = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData); string[] tempstr = documentsFolder.Split('\\')
// 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);
感谢您的帮助。当连接字符串错误时,会出现此错误 在您的
@“数据源={0}”
必须放置数据源而不是数据源
希望有帮助。如果您总是需要本地而不是漫游,那么使用
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
可以大大简化此过程。还可以考虑使用或至少代替循环中的字符串连接。谢谢!感谢谷歌,这是该错误消息的第二个结果。。。我本可以花很长时间来寻找这个细节的。
SQLiteConnection conn = new SQLiteConnection(connectionString);
conn.Open();