jeudi 3 mars 2016

C# Sqlite using Dapper multithreaded access

I'm fairly new to using MicroORMs and could use some suggestions on how to solve the issue of multithreaded access to my database. Based on what I've seen best practice seems to dictate that I open the database for queries like so.

using (var db = new SQLiteConnection(this.connectionString))
{
     queryResult = await db.QueryAsync(sqlQuery, args);
}

The question becomes how do I handle request such as the one above coming in from multiple threads because I'm getting exceptions (not surprisingly) because my database file is already being accessed from another thread. I am aware that I could probably use locks or a mutex to get around this issue but is that the only way?

Aucun commentaire:

Enregistrer un commentaire