- Home /
Can SQLite store DB in memory with Mono/Unity
I'm trying to speed up any code to do with my local SQlite database. One way i read was to store the database in memory only, Only thing is i cannot get that to work. I can't find any API reference for the Mono version either. I've tried:
_dbc_m = new SqliteConnection("URI=memory:");
_dbc_m = new SqliteConnection("URI=:memory:");
_dbc_m = new SqliteConnection(":memory:");
Answer by DanielGilbert · Aug 23, 2016 at 05:50 AM
Depending on the version of Mono.Data.Sqlite, you might also try:
URI=file::memory:,version=3
Another option would be to simply leave the filename empty. This will create a temporary file on disk, but most of the time, SQLite will de-facto work in-memory:
Even though a disk file is allocated for each temporary database, in practice the temporary database usually resides in the in-memory pager cache and hence is very little difference between a pure in-memory database created by ":memory:" and a temporary database created by an empty filename. The sole difference is that a ":memory:" database must remain in memory at all times whereas parts of a temporary database might be flushed to disk if database becomes large or if SQLite comes under memory pressure.