关于事务中插入两条以不同字段分表第一个能正常执行至第二个直接卡住了 返回

SqlSugar 沟通中
24 146

image.png

热忱回答24

  • image.png类1

    0 回复
  • image.png类二

    0 回复
  • 我想是不是共用了一个 newDb.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new SplitTableService();导致的

    0 回复
  • 看不出问题,提供完整的DEMO

    0 回复
  • 删掉obj和bin上传就行了

    0 回复
  • 0 回复
  • 这是代码麻烦有空帮看看谢谢弄了一晚上

    0 回复
  • 其实那两个模式类是一样的只是自定义分表的时候设置的分表字段不一样所以只能一个模形分开两个模形操作不同的分表

    0 回复
  • 不知道有没有方法在一个模型上标上对两个分表字段标上Splitfield然后实名两个不一样的规则分表

    0 回复
  •  在看了

    0 回复
  • @fate sta:将事务去掉就可以正常运行了所以应该是不兼容事务

    0 回复
  • image.png

    0 回复
  • image.png

    0 回复
  • DEMO成功跑完,你测试过了吗?

    0 回复
  • 新建一个空库跑一下看看我这边正常

    0 回复
  • @fate sta:好的我试试

    0 回复
  • image.png

    0 回复
  • 一直给锁不知道咋回事


    0 回复
  • 不知道是否跟连接字符串有关不能否将您的连接字符串发一下将ip去掉就好


    0 回复
  • // See https://aka.ms/new-console-template for more information
    using ConsoleApp1;
    using Microsoft.Graph.Models;
    using SqlSugar;
    using System.DirectoryServices.Protocols;
    
    Console.WriteLine("Hello, World!");
    
    ConnectionConfig configs=new ConnectionConfig()
    {
        ConfigId = 1,
        DbType = DbType.SqlServer,
        ConnectionString = "server=.;uid=sa;pwd=sasa;database=SqlSugar5Demo",//这里的连接字符串随真实环境填写
        IsAutoCloseConnection = true
    };
    
    using (SqlSugarClient Db=new SqlSugarClient(configs))
    {
        CardByChannelName req01 = new CardByChannelName()
        {
          Id= 0,
          CreateTime= "2023/9/6 22:21:00",
          ChannelName= "大连联通",
          ChannelType= "语音卡",
          NetworkMode= "4G",
          RealName= "需要实名",
          Appid= "wxcb70879d8a25f479",
          Iccid= "89860923760003020900",
          FpState= "未分配",
          Misidn= "14662814722",
          CradState= "库存期",
          UserName= "Admin",
          MealId= "6",
          Silentperiod= "12",
          ShowMealId= "0|1"
        };
    
        CardByUser req02 = new CardByUser()
        {
            Id = 0,
            CreateTime = "2023/9/6 22:21:00",
            ChannelName = "大连联通",
            ChannelType = "语音卡",
            NetworkMode = "4G",
            RealName = "需要实名",
            Appid = "wxcb70879d8a25f479",
            Iccid = "89860923760003020900",
            FpState = "未分配",
            Misidn = "14662814722",
            CradState = "库存期",
            UserName = "Admin",
            MealId = "6",
            Silentperiod = "12",
            ShowMealId = "0|1"
        };
        var newDb = Db.CopyNew();
        try
        {
            newDb.Ado.BeginTran();
            newDb.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new SplitTableService();
            newDb.Insertable(req01).SplitTable().ExecuteReturnSnowflakeId();
            newDb.Insertable(req02).SplitTable().ExecuteReturnSnowflakeId();
            newDb.Ado.CommitTran();
            return;
        }
        catch
        {
            newDb.Ado.RollbackTran();
            return;
        }
    }


    0 回复
  • 好的谢谢

    0 回复
  • 换了服务器和sqlserver就好了   真是不懂什么原因了

    0 回复
  • @話多心涼┴:解决就行,我这边也正常的,可能系统问题

    0 回复
  • @fate sta:好的谢谢

    0 回复