Hi all, I am on v5.0.1 and I don't understand how to set the connection as shared. I have tried with both Mode=Shared and Connection=Shared but if I open the database in LiteDB Studio and then in my app or the opposite, I receive an exception stating that the file is already opened in another process.
Can you tell me what is the correct way of setting the connection as shared?
Thanks in advance
@darcome Here's a working example of how to run LiteDB in Shared connection mode
class Program
{
static async Task Main(string[] args)
{
await Task.WhenAll(
Action(),
Action());
}
private static async Task Action()
{
using var db = new LiteDatabase(@"Filename=database.db;Password='1234';connection=shared");
await Task.Delay(1000);
}
}
If you prefer using a connectionString object instead of a literal string, you can also replace the string with something like this
new ConnectionString(@"database.db")
{
Password = "1234",
Connection = ConnectionType.Shared
};
@JensSchadron THank you very much! It worked like a charm!
I see that I cannot use shared mode when I also specify Upgrade=true?
Most helpful comment
@JensSchadron THank you very much! It worked like a charm!