首页 > 其他分享 >The transaction associated with this command is not the connection‘s active

The transaction associated with this command is not the connection‘s active

时间:2023-04-16 10:33:44浏览次数:44  
标签:事务 更新 connection command 信息 active logger trans ex


1、出现问题原因

接口接收入参为数组类型,遍历数组操作时,事务写在了循环里,待下一次循环时事务非此连接的事务导致出现如题错误,接口传参数组形式如下:

[
    {
        "id": 1,
        "infos": [
            {
                "id": "1",
                "name": "小华",
                "age": "18"
            }
        ]
    },
    {
        "id": 2,
        "infos": []
    }
]

2、解决办法

将循环中需要更新的数据放入到列表中,在循环外用事务执行批量更新,以此使事务处于连接的活动事务中即可。部分示例代码如下:

// ...处理循环信息
var trans = _people.BeginTransaction();
try
{
    // 更新人员信息
    var updatePeople = _people.UpdateRange(updatePeopleInfoList);
    if(updatePeopleInfoList.Count == 0) updatePeople = true;
    // 更新人员附属信息
    var updatePeopleItem = _peopleItem.UpdateRange(updatePeopleItemList);
    if(updatePeopleItemList.Count == 0) updatePeopleItem = true;
    if(updatePeople && updatePeopleItem)
    {
        trans.Commit();
        _logger.LogDebug($ "[更新人员信息成功]", "111111");
    }
    else
    {
        trans.Rollback();
        _logger.LogError($ "[更新人员信息失败]{args.ToJson()}");
        return ErrorResult < long > ($ "更新人员信息失败", "111112");
    }
}
catch(Exception ex)
{
    trans.Rollback();
    _logger.LogError($ "[更新人员信息失败]{ex}", ex.Message);
    return ErrorResult < long > ("系统繁忙,请重新获取", "111150");
}

标签:事务,更新,connection,command,信息,active,logger,trans,ex
From: https://blog.51cto.com/u_10040183/6193347

相关文章

  • Command: man
     man[options...][SECTION]PAGE...   -l--local-fileinterpretPAGEargumentsaslocalfilenamesman-l/usr/share/man/man1/ls.1.gz ......
  • Java连接RabbitMQ报错:An unexpected connection driver error occured(偶尔能连上)
    1、查看rabbitMq的状态。输入命令:rabbitmqctlstatus,发现没有报错,但是rabbit中的host是root,并不是ip地址,所以连接不上。 2、运行命令:echo【ip地址】root>>/etc/hosts。将RabbitMQ服务所在的IP地址添加到/etc/hosts中。 ......
  • How to use command line find all users on Linux All In One
    HowtousecommandlinefindallusersonLinuxAllInOneLinux系统中一切皆文件,就像js中一切皆对象一样/etc/passwd#password$cat/etc/passwdRaspberryPipi@raspberrypi:~$cat/etc/passwd|greppipi:x:1000:1000:,,,:/home/pi:/bin/bashpi@raspbe......
  • how to create one command line configuration tool with shell language on Linux A
    howtocreateonecommandlineconfigurationtoolwithshelllanguageonLinuxAllInOne如何在Linux上用shell语言创建一个命令行配置工具RaspberryPiconfigurationtool$sudoraspi-config#等价于,直接修改$sudovim/boot/config.txt$DISPLAY#设......
  • Linux input and ouput command < symbol & > symbol All In One
    Linuxinputandouputcommand<symbol&>symbolAllInOneleftinput/rightoutput<向左侧输入#把文件内容复制到剪贴板中✅$pbcopy<filename.txt>向右侧输出#把剪贴板内容粘贴到文件中✅$pbpaste>filename.txtdemos$echo"helloworld">......
  • The Network Adapter could not establish the connection
    1、oracle配置oracle9i2中把C:\oracle\ora92\network\admin目录下的listener.ora和tnsnames.ora(注意:连接远程计算机中oracle数据库的配置中的host不可修改。)File: C:\oracle\ora92\network\admin\listener.oraLISTENER=(DESCRIPTION_LIST=(DESCRIP......
  • Linux copy from pipe command All In One
    LinuxcopyfrompipecommandAllInOneshutdown#Linux关机$shutdown--help$manshutdownRaspberryPi#RaspberryPi???$manshutdown|???macOS#macOS✅$manshutdown|pbcopy#手动复制粘贴到shutdown.md✅$manshutdown#自动导出❌$......
  • org.dom4j.DocumentException: Connection timed out: connect Nested exception: Con
    今天用dom4j解析xml文件时遇到了一个问题org.dom4j.DocumentException:Connectiontimedout:connectNestedexception:Connectiontimedout:connect atorg.dom4j.io.SAXReader.read(SAXReader.java:484) atorg.dom4j.io.SAXReader.read(SAXReader.java:321) atcom......
  • 微信小程序云开发中的command简介
    微信小程序云开发(WeChatMiniProgramCloudDevelopment)是微信官方推出的一种简化小程序开发的方案。它提供了一个完整的后端云服务,支持数据库、存储、云函数等功能。在云开发中,Command是一个重要的概念,主要用于操作数据库。Command是数据库命令的构造器,它用于构造复杂的数据......
  • GnuTLS recv error (-110): The TLS connection was non-properly terminated问题的解
    1. sudoapt-getupdate2.sudoapt-getinstallbuild-essentialfakerootdpkg-dev3.sudoapt-getbuild-depgit4.mkdir~/git-openssl5.cd~/git-openssl6apt-getsourcegit ......