如何创建一个内存中的SQLite数据库?

55

我曾尝试过使用 SQLiteConnection(":memory:")SQLiteConnection("sqlite::memory:") ,但两者都因为'无效的ConnectionString格式'而失败。

3个回答

95
尝试
var connection = new SQLiteConnection("Data Source=:memory:");

3
对我来说这个不起作用。我收到一个异常:“路径格式不合法。” - Steztric
@Steztric 尝试不在 Data Source => new SqliteConnection("DataSource=:memory:") 之间加空格。 - AZ_
var connection = new SqliteConnection("Filename=:memory:"); - Skorunka František

6
我正在使用这个:

var connectionStringBuilder = new SQLiteConnectionStringBuilder { DataSource = ":memory:" };
var connection = new SQLiteConnection(connectionStringBuilder.ToString());

4

2
还有更多信息吗?使用var connection = new SqliteConnection("FullUri=file::memory:?cache=shared;");时,我收到了System.ArgumentException: Keyword not supported: 'fulluri'。 - Andez
你使用的小写的 SqliteConnection 是来自不同的包 Microsoft.Data.Sqlite,它不支持 FullUri 参数。 - ghord

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接