事务未连接,或被断开连接错误 [英] Transaction not connected, or was disconnected error

查看:316
本文介绍了事务未连接,或被断开连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到

事务未连接或连接断开错误"

"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
    }

如果将文件从文件批量插入到临时数据库的查询失败,我将在tran.Commit/rollback上收到此错误.

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

推荐答案

批量插入是Insert语句的组合,因此,如果插入失败,则不会回滚事务,因此,如果您确实要捕获错误,请尝试使用Try and在BEGIN和END事务内捕获块

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

这篇关于事务未连接,或被断开连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆