How can I create an in memory sqlite database?
Asked Answered
N

3

55

I have tried SQLiteConnection(":memory:") and SQLiteConnection("sqlite::memory:") but both of these fail with 'Invalid ConnectionString format'

Nauplius answered 7/2, 2012 at 9:3 Comment(0)
R
95

try

var connection = new SQLiteConnection("Data Source=:memory:");
Rhapsodize answered 7/2, 2012 at 9:5 Comment(3)
This doesn't work for me. I get an exception 'The path is not of a legal form.'Autonomic
@Autonomic try not putting a space between Data Source => new SqliteConnection("DataSource=:memory:")Morganstein
var connection = new SqliteConnection("Filename=:memory:");Creosote
Q
7

I'm using this:

var connectionStringBuilder = new SQLiteConnectionStringBuilder { DataSource = ":memory:" };
var connection = new SQLiteConnection(connectionStringBuilder.ToString());
Qualifier answered 16/10, 2017 at 9:7 Comment(0)
P
4

Maybe it's too late, but FullUri=file::memory:?cache=shared; is working.

It's knowledge from forum question

Padegs answered 21/2, 2017 at 7:20 Comment(2)
Any more info? I get System.ArgumentException : Keyword not supported: 'fulluri'. using var connection = new SqliteConnection("FullUri=file::memory:?cache=shared;");Architect
@Andrez Lowercase SqliteConneciton you are using is from different package Microsoft.Data.Sqlite which doesn't work with FullUri parameter.Piano

© 2022 - 2024 — McMap. All rights reserved.