Deadlocks causing 'Server failed to resume the transaction' with NHibernate and distributed transactions

前端 未结 4 1671
耶瑟儿~
耶瑟儿~ 2021-02-20 00:24

We are having an issue when using NHibernate with distributed transactions.

Consider the following snippet:

//
// There is already an ambient distributed         


        
4条回答
  •  梦毁少年i
    2021-02-20 00:30

    It is an NHibernate issue. NHibernate is not opening and closing the connection on the same thread, which is not supported by ADO.NET. You can work around it by opening and closing the connection yourself. NHibernate will not close the connection unless it has also opened it.

    Workaround

    var connection = ((SessionFactoryImpl)_sessionFactory).ConnectionProvider.GetConnection();
    using(var session = _sessionFactory.OpenSession(connection))
    {
       //do database stuff
    }
    connection.Close();
    

提交回复
热议问题