Transaction not connected, or was disconnected error

ぃ、小莉子 提交于 2019-12-24 16:27:31

问题


I am getting

"Transaction not connected, or was disconnected error"

error when the transaction is either committed/rolled back after doing a bulk insert (along with some other operations).

using(var tran = Session.Session().BeginTransaction(IsolationLevel.Serializable))
    {
       // do something
       fullSession.Session().CreateSQLQuery(query).ExecuteUpdate();// this query bulk insert in a temp db
       // do something else
       tran.Commit()/ tran.RollBack();// if transaction is active and not already rolled back/committed
    }

If the query to bulk insert from a file into a temp database fails, I get this error on tran.Commit/rollback.


回答1:


Bulk Insert is a combination of Insert statements so if it fails it doesn't roll back the transaction so if you really want to catch the error try using Try and catch block inside BEGIN and END transaction




回答2:


I was getting this exact same error using NHybernate while persisting an entity that had a property of type System.Data.SqlTypes.SqlDateTime? (Nullable).

Changing the property to a regular System.DateTime? fixed the problem.




回答3:


I had some problem, but it gone after I close connection in MS SQL Managment studio.



来源:https://stackoverflow.com/questions/10839399/transaction-not-connected-or-was-disconnected-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!