I use MySQL (it does not support MARS), and I try to run in parallel multiple SELECT
s. The connection string is the same, however for each SELECT
I create another db context.
It looks like this:
using (var db = DataContextCreator.Instance.Create())
{
return db.Customers
.Where(it => it.customer_Id > 10)
.Detach(db.Customers);
}
A word about Detach
-- it is helper method which takes a record or bunch of records. In the second case it makes the list of them (to make them concrete data), and detaches the records from db context (so GC could free the db context) returning back the detached data.
For now it gives me an error about dreadful "There is already an open DataReader associated with this Connection which must be closed first". Since I don't explicitly use DataReader I would like be 100% sure of the reason.
Is it because I use single connection string to create all those db contexts? Or put in other words -- is MARS required for above scenario?
I am asking because I would like not to reinvent the wheel, and because all my queries are rather small and quick I am thinking about stupid workaround -- using lock in db context creator. This way each block querying database would have guarantee that is not executed in parallel with another one.