“数据源不能为空。”是什么意思?使用“内存:打开内存数据库”意思是?
我最近将 SQL Server 数据库转换为 SQLite DB。但是当我尝试使用 .Open()
打开 SQLite 时,它会抛出此错误:
Data Source cannot be empty. Use :memory: to open an in-memory database
编辑:添加连接字符串:
ConnectionString = @"Data Source=D:\XXX.db;Version=3";
connection = new SQLiteConnection(connectionString);
connection.Open();
为什么我会得到这个?我将相同的 SQL Server 数据库转换为 SQL CE 和 mySQL,但没有收到这些错误。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
数据源后面有一个空格:
Data Source= D:\XXX.db
。此外,在您的复制/粘贴中,连接字符串没有结束引号。这是适合我的测试工具的连接字符串: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:最近,当我实际尝试使用 SQLite 的内存版本时,我遇到了同样的错误。
我设置连接如下:
并收到错误
,然后我将其更改为以下代码,请注意“SQL”部分不再大写:
现在它可以工作了。
工作的非大写版本来自 Microsoft.Data.Sqlite.SqliteConnection 命名空间,而 SQLite 版本来自 System.Data.SQLite.SQLiteConnection (我引用了版本 1.0.113.6)。
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:
And getting the error
I then changed it to this code, note the 'SQL' part is no longer capitalised:
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).
您尚未提供数据源名称,即 sqlite 文件所在的位置。
You haven't provided a data source name, aka where the sqlite file exists.
因为您的数据源是空的。将数据源参数添加到连接字符串中。在打开 Sqlite 数据库之前。
Because your Data Source is empty. Add the Data Source paramater to your connection string. before opening the Sqlite database.