Please help..
I have an MVC 3 application that allows multiple users to run some
custom process.
The problem beggins when 2 users try to create a process at the same
time, then I get this exception:
Transaction (Process ID 55) was deadlocked on lock resources with
another process and has been chosen as the deadlock victim. Rerun the
transaction.
Exception has been thrown.
NHibernate.TransactionException: Transaction not connected, or was
disconnected
at NHibernate.Transaction.AdoTransaction.CheckNotZombied() in d:
\CSharp\NH\NH\nhibernate\src\NHibernate\Transaction
\AdoTransaction.cs:line 410
at NHibernate.Transaction.AdoTransaction.Rollback() in d:\CSharp\NH
\NH\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:line 241
Each my query/crud is incapsulated in the follwing helper:
public static class SessionHelper
{
[DebuggerStepThrough]
public static TResult Transact<TResult>(Func<TResult> func)
{
var session =
ObjectFactory.Container.GetInstance<ISession>();
if (!session.Transaction.IsActive)
{
using (var tx = session.BeginTransaction())
{
try
{
result = func.Invoke();
tx.Commit();
}
catch (Exception e)
{
Logger.Error(e.ToString(), e);
tx.Rollback();
session.Close();
throw;
}
}
return result;
}
Logger.FormatInfo("Transaction is allready open");
result = func.Invoke();
}
so in example I use: var result =
SessionHelper.Transact(()=>Session.Get<Process>(id));
I use StructureMap to inject ISession to all classes that needs it
like this:
x.For<ISessionFactory>().Singleton().Use(CreateSessionFactory);
x.For<ISession>().HybridHttpOrThreadLocalScoped().Use(context =>
context.GetInstance<ISessionFactory>().OpenSession());
What can I do to resolve this error?
Please is very important.
--
You received this message because you are subscribed to the Google Groups
"nhusers" 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/nhusers?hl=en.