sqlite 连接报错 返回

SqlSugar 老数据
14 1882
该叫什么 lihui 发布于2023/2/27
悬赏:5 飞吻

再使用查询user表正常的情况下 , 使用

db!.Storageable(data).ExecuteCommand()
插入数据报下面的连接错误



SqlSugar.SqlSugarException: 中文提示 :  连接数据库过程中发生错误,检查服务器是否正常连接字符串是否正确,错误信息:ConnectionString must be set before Open can be called.DbType="Sqlite";ConfigId="061cefed-fad2-4a3d-84c5-8b8d7b714a8f".

English Message : Connection open error . ConnectionString must be set before Open can be called.DbType="Sqlite";ConfigId="061cefed-fad2-4a3d-84c5-8b8d7b714a8f"

   at SqlSugar.Check.Exception(Boolean isException, String message, String[] args)

   at SqlSugar.AdoProvider.CheckConnection()

   at SqlSugar.SqliteProvider.GetCommand(String sql, SugarParameter[] parameters)

   at SqlSugar.AdoProvider.GetDataReader(String sql, SugarParameter[] parameters)

   at SqlSugar.QueryableProvider`1.GetData[TResult](KeyValuePair`2 sqlObj)

   at SqlSugar.QueryableProvider`1._ToList[TResult]()

   at SqlSugar.QueryableProvider`1.ToList()

   at SqlSugar.Storageable`1.<>c__DisplayClass31_0.<ToStorage>b__1(List`1 item)

   at SqlSugar.ContextMethods.PageEach[T](IEnumerable`1 pageItems, Int32 pageSize, Action`1 action)

   at SqlSugar.Storageable`1.ToStorage()

   at SqlSugar.Storageable`1.ToStorage()

   at SqlSugar.Storageable`1.ExecuteCommand()

   at DetonatorFactoryApp.LocalDatabase.SqlSugarServices.InsertUser(User data) in C:\Users\800182\RiderProjects\Holyview\DetonatorFactoryApp.LocalDatabase\SQLSugarServices.cs:line 183

   at DetonatorFactoryApp.ViewModels.LoginViewModel.<GoLogin>g__UserLogin|66_0(NetWorkManage service) in C:\Users\800182\RiderProjects\Holyview\DetonatorFactoryApp\ViewModels\LoginViewModel.cs:line 297


热忱回答14

  • fate sta fate sta VIP0
    2023/2/27

    IsAutoClose=true有没有打开

    0 回复
  • fate sta fate sta VIP0
    2023/2/27

    如果是偶发错误看这个:https://www.donet5.com/Home/Doc?typeId=1224

    0 回复
  • lihui lihui VIP0
    2023/2/27

    @fate sta

    = SqlSugarScope(
        ConnectionConfig
        {
            = DbType.= = InitKeyType.= ConfigureExternalServices
            {
                = (cp) =>
                {
                    p.= UtilMethods.(p.)(p.== && NullabilityInfoContext()
                            .(c).NullabilityState.)
                    {
                        p.= }
                }= (p) => {
                    p.= UtilMethods.(p.)}
            }
        }(SqlSugarClient client)
        {
            client..= (s) =>
            {
                .(LogTemplates.LogFileType.s)}})


    0 回复
  • lihui lihui VIP0
    2023/2/27

    @fate sta:不是偶发的, 每次必现

    0 回复
  • fate sta fate sta VIP0
    2023/2/27

    连接字符串发一下

    0 回复
  • fate sta fate sta VIP0
    2023/2/27

    db.CurrentConfig.ConnectionString把这个值拿出来

    0 回复
  • lihui lihui VIP0
    2023/2/27

    @fate staimage.pngDataSource=C:\Users\800182\RiderProjects\Holyview\DetonatorFactoryApp\bin\Debug\net6.0-windows\database\detonator_factory_app.db

    0 回复
  • 可乐 可乐 VIP0
    2023/2/27

    麻烦问一下这个字符串有什么问题么?


    server=localhost;Database=simulation;Uid=root;Pwd=123456;charset=utf8mb4


    0 回复
  • 可乐 可乐 VIP0
    2023/2/27

    @fate sta

    麻烦问一下这个字符串有什么问题么?


    server=localhost;Database=simulation;Uid=root;Pwd=123456;charset=utf8mb4


    0 回复
  • lihui lihui VIP0
    2023/2/27

    现在我再创建db对象,的时候,createDatabase, 又可以了, 不明白是什么情况

    0 回复
  • fate sta fate sta VIP0
    2023/2/27

    @lihui:你没创建库吧,

    0 回复
  • fate sta fate sta VIP0
    2023/2/27

    创建库只执行一次不要写业务里面

    0 回复
  • lihui lihui VIP0
    2023/2/27

    @fate sta:创建了的, 另一张表都插入数据了, 只是初始化db,  和 createdatabase  没写在一个方法里

    0 回复
  • fate sta fate sta VIP0
    2023/2/27

    @lihui:那还有问题吗

    0 回复