My team has been running into a problem when using DifferentDatabaseScope. I have attached a patch that fixes the issue, but let me describe the issue first...
When using DifferentDatabaseScope in the following manner:
using (var s = new SessionScope())
{
IDbConnection conn1;
//initialize and open conn1
using (var diffScope1 = new DifferentDatabaseScope(conn1))
{
}
conn1.Dispose();
IDbConnection conn2;
//initialize and open conn1 using the *SAME* connection string as conn1
using (var diffScope2 = new DifferentDatabaseScope(conn2))
{
}
conn2.Dispose();
}
We started to see all kinds of "connection already closed/disposed" errors in
the second DifferentDatabaseScope. I tracked the problem down to the
Castle.ActiveRecord.Framework.Scopes.KeyHolder class and the
DifferentDatabaseScope.GetSession method. GetSession looks up a session using
a key that is composed of a connection string and a few other items. The
problem is that the keys for conn1 and conn2 are the same, so all operations in
the second scope were trying to use conn1.
My patch adds the hashcode of the connection to the KeyHolder class, so that
connections can be distinguished even when they have the same connection
strings. This is probably not bullet proof either, but in my tests (PostgreSQL
and SQL Server) it works like a charm.
I would be happy to create an issue to document this patch, but I wanted to put
it out there first to make sure it's not something that someone's already aware
of.
-Tyler
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Development List" 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/castle-project-devel?hl=en
-~----------~----~----~----~------~----~------~--~---
DifferentDatabaseScope_include_conn_hashcode.patch
Description: DifferentDatabaseScope_include_conn_hashcode.patch
