常见问题汇总

1、已有打开的与此 Command 相关联的 DataReader,必须首先将它关闭。

There is already an open DataReader associated with this Connection which must be closed first.

或者出现 connection is closed

出现这个错一般是线程安全引起的

解决方案: https://www.donet5.com/Home/Doc?typeId=1224


2.The connection does not support MultipleActiveResultSets

 (1)、SqlSugarClient 替换成 SqlSugarScope ,因为SqlSugarScope 是线程安全对象代码容错率高

   具体用法: https://www.donet5.com/Home/Doc?typeId=1181

   (2)  、异步用法错引起的 ,排查没用Await调用的异步方法

Public void  GetAll(){  异步方法  }//错误
Public async Task GetAll(){  异步方法  }//错误
Public async Task GetAll(){  await  异步方法  }//正确


 3. max_allowed_packet  MYSQL

一般提示这个错可能一次更新的内容太多,可以分页操作

db.Utilities.PageEach(allList, 10000 ,pageList=> {
  db.Insertable(pageList).ExecuteCommand();
});


4、实体与表映射出错

出现这个错一般是 数据库中的类型和实体中的类型不一样引起的,可以注释实体类中的字段进行排除哪个字段引起的


5、Only one primary key

当前功能只支持单主键,看看实体类有没有与置主键,并且主键只能有一个,或者数据库是否有主键并且只能有一个


6、未安装或者版本冲突

打开 Web层或者WinFom的项目,查看 App.config 有没有下面这种兼容配置,如果没这种配置这个DLL就会报错,

想办法搞出来,一般NUGET在当前项目安装 SqlSugar然后在安装报错的DLL NUGET会自动添加到app.config

例1:

  
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
      </dependentAssembly>

例2:

  <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.27.0" newVersion="8.0.27.0" />
   </dependentAssembly>

如果没有先安装SqlSugar,在安装报错dll


7、雪花ID重复

 不同电脑 本地或者服务器 要用不同的WorkId ,如果服务器时间回调也要设置WorkId


8、Cannot Open when State is Connecting.

解决方案: https://www.donet5.com/Home/Doc?typeId=1224


9、连接不上数据库

原生能用SqlSugar就能用,一定要用db.CurrentConfig.ConnectionString保证是同一个字段串,并且在同一个程序

//用原代码进行测试
//SqlSerer 
var conn=new SqlConnection(db.CurrentConfig.ConnectionString).Open();
conn.Close();

//MySql用
var conn=new MySqlConnection(db.CurrentConfig.ConnectionString).Open();
conn.Close();

//不同的数据库不同 ,一般根据DbType+Connection


10、截断二进制

数据库字段太小引起的

文档:SqlSugar5.0