Munna Extreme
Munna Extreme

Reputation: 390

SQLite Shared Cache Database

I had created a shared in-memory database using the following code, but the problem is, even I close the connection or restart the machine, the data is still available.

I didn't understand how the data is persistent and where it is physically stored.

using (SQLiteConnection database = new SQLiteConnection("file: empDB ? mode = memory & cache = shared"))
            {
                database.CreateTable(emp.GetType());
                database.Insert(emp);
                var value = database.Query<Emp>("select * from emp;select * from emp;");
            }

Upvotes: 1

Views: 1608

Answers (1)

Nikita
Nikita

Reputation: 6427

To achieve expected behavior you could use FullUri syntax, e.g:

using (SQLiteConnection database = new SQLiteConnection("FullUri=file:empDB?mode=memory&cache=shared"))
{
  database.Open();
  // ....
}

I didn't understand how the data is persistent and where it is physically stored.

Database file with name empDB is created in your application working directory when you use your original connection string, e.g. FullUri=file: empDB ? mode = memory & cache = shared. This file is reused when you run the application again.

Upvotes: 3

Related Questions