On Sat, 2009-06-13 at 07:10 -0700, greyman wrote:
> I'm attempting to use DbLinq in an application that runs a 10 to 20
> concurrent threads which access the database. I've been tracking down
> sporadic exception related to DbLinq operations and from what I've
> been able to glean so far it looks like the DatabaseContext class is
> caching the database connection object and on each access is checking
> whether the connection is open or not. If this is the case it's a
> problem when multiple threads are using the same DataContext object
> since they'll end up with multiple threads using the connection at the
> same time and having a situation where the responses will be
> incorrectly parsed.

From:
http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx

        Any public static (Shared in Visual Basic) members of this type
        are thread safe. Any instance members are not guaranteed to be
        thread safe.

Granted, this is for .NET's DataContext type, but DbLinq aims to
implement the same API, with the same constraints, as .NET's API.

In short, DataContext is NOT thread safe, never has been, likely never
will be, so your scenario is broken by design.

Sorry.

> For connection pooling in ADO.Net a new database connection should be
> created each time a databse connection object is needed and the
> connection pool takes care of making connection re-use efficient. That
> solves the problem for multi-threaded apps as long as they don't try
> and pass a database connection object around which they shouldn't.

This is likely a good idea anyway (and is now at the end of my rather
lengthy TODO list).

That said, following this behavior will not magically make DataContext
thread safe, and thus won't make DataContext suitable for your uses.
(For example, objects returned by queries are "tied" to the DataContext
instance that created them for change tracking purposes, and these
objects are stored in a collection, so your multi-threaded access of the
DataContext may very well corrupt this collection, which will cause no
end of debugging pain....)

 - Jon



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to