Multithread/multiprocess access to database

Dec 27, 2014 at 8:14 PM
Hi,

I read somewhere that multithreading/multiprocess access support was introduced in NDatabase 3.6. Is this documented anywhere? I'm having some problems with accessing the db file from two processes, what happens is (I assume) that one of the processes locks the file, and then the other process has to wait several seconds before the file is unlocked again. None of the processes ever keep the connection open for more than a few milliseconds.

What I do is basically this:
using (var fact = OdbFactory.Open(_fullPathToDb))
                {
                    var objs = fact.Query<SomeClass>().Execute<SomeClass>();
                    // use objs for whatever I need to do
                 }
Did 3.6 introduce any new ways to access the database, which allow me to do this without blocking? Or is there no way to avoid this problem in NDatabase?
Mar 5, 2015 at 8:53 PM
Curious if you ever got a response to this (directly), or you figured out an overloaded method or something that helps?

I was thinking of using this in a .Net4 set of applications, but they would need to cooperatively be able to read/write to the same local database in a relatively performant manner.

Thanks,
AJ
Mar 5, 2015 at 9:01 PM
No, I didn't find a solution to this. Since my application is really quite simple, I just switched to SQLite instead, which seems to be really good at concurrency (but of course forces me to think SQL again, which I was trying to avoid).

Henrik
Mar 5, 2015 at 9:34 PM
Thanks for the reply. Did you use the C# port of SQLite or the native version with a .Net wrapper of some kind?

I have used SQLite before and like it, but can't remember how to access the DB file from multiple processes concurrently...

-AJ
Mar 6, 2015 at 7:42 AM
It's been some time, so I don't remember exactly, but from my source code it looks like I used System.Data.SQLite.

Regarding concurrency, I think SQLite handles it for you, by locking the file whenever it needs to write to it. However, I recommend using transactions, as they will (if I've understood correctly) lock the file for the entire duration of the transaction.