Recently I browse the micro ORMs and I like Massive for SQLite because its simple. But I have now an issue.
I am just running some select statement followed by an update statement but I am getting an exception. Below is my code :
var tbl = new Cust();
var customers = tbl.All(where: "CustomerID > @0", orderBy: "FirstName", columns: "CustomerID,FirstName", args: 4);
var firstCustomerName= customers.First().FirstName;
var c = tbl.Update(new { FirstName = "Updated2" }, 4); //Exception is here!
//Same happens even when using another object
//var tbl2 = new Cust();
//tbl2.Update(new { FirstName = "UpdatedName" }, 4);//Exception is here!
The Exception Message is : "Database is locked", at a method below in the Massive.SQLite source
public virtual int Execute(IEnumerable<DbCommand> commands)
{
var result = 0;
using (var conn = OpenConnection())
{
using (var tx = conn.BeginTransaction())
{
foreach (var cmd in commands)
{
cmd.Connection = conn;
cmd.Transaction = tx;
result += cmd.ExecuteNonQuery();
}
tx.Commit();//Here is the Exception!
}
}
return result;
}
When I look at Massive.SQLite source i see that massive never closes connections but instead relays on the using statement to dispose the connection object, as you can see in the above code.
OpenConnection() in the above code is a method that returns a new connection every time called.
public virtual DbConnection OpenConnection()
{
var result = _factory.CreateConnection();
result.ConnectionString = ConnectionString;
result.Open();
return result;
}
If the case is that Massive is not closing the connection, and according to this SO question Sqlite is not good at concurrent connections and I am supposed to close it, how can I close it then? - the connection is not exposed to me.
I want to hear the best practice from developers using Massive with SQLite.