“数据源不能为空。”是什么意思?使用“内存:打开内存数据库”意思是?

发布于 2024-09-29 02:22:10 字数 432 浏览 0 评论 0原文

我最近将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

峩卟喜欢 2024-10-06 02:22:10

数据源后面有一个空格:Data Source= D:\XXX.db。此外,在您的复制/粘贴中,连接字符串没有结束引号。这是适合我的测试工具的连接字符串:

@"Data Source=C:\Temp\Test.db3;Pooling=true;FailIfMissing=false;Version=3"

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"
寄人书 2024-10-06 02:22:10

最近,当我实际尝试使用 SQLite 的内存版本时,我遇到了同样的错误。

我设置连接如下:

var connection = new SQLiteConnection("Filename=:memory:");
connection.Open();

并收到错误

数据源不能为空。使用 :memory: 打开内存中

,然后我将其更改为以下代码,请注意“SQL”部分不再大写:

var connection = new SqliteConnection("Filename=:memory:");
connection.Open();

现在它可以工作了。

工作的非大写版本来自 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:

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

戏舞 2024-10-06 02:22:10

您尚未提供数据源名称,即 sqlite 文件所在的位置。

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

熟人话多 2024-10-06 02:22:10

因为您的数据源是空的。将数据源参数添加到连接字符串中。在打开 Sqlite 数据库之前。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文