.net core 3.1 WPF中使用SqlSugar操作连接Sqlite字符串连接异常问题(看着一篇就够了)

如果看完下面内容还不知道如何解决可以查看官方文档

异常错误代码如下

SqlSugar.SqlSugarException    HResult=0x80131500    
Message=中文提示 :   连接数据库过程中发生错误,检查服务器是否正常连接字符串是否正确, 错误信息: Connection string keyword 'version' is not supported. For a possible alternative, see https://go.microsoft.com/fwlink/?linkid=2142181..
English Message : Connection open error . Connection string keyword 'version' is not supported. For a possible alternative, see https://go.microsoft.com/fwlink/?linkid=2142181.
  Source=SqlSugar   StackTrace:    在 SqlSugar.Check.Exception(Boolean isException, String message, String[] args)    在 SqlSugar.SqliteProvider.get_Connection()    在 SqlSugar.AdoProvider.CheckConnection()    在 SqlSugar.DbMaintenanceProvider.IsAnySystemTablePermissions()    在 SqlSugar.DbFirstProvider.Init()    在 SqlSugar.SqlSugarProvider.get_DbFirst()    在 SqlSugar.SqlSugarClient.get_DbFirst()    在 DropdownMenu.DB.SqlSugarHelper.InintialDB() 在 D:\ComPany\xxx\dotnet\wpf\StudayAdonisUI\DropdownMenu\DB\SqlSugarHelper.cs 中:27 行    在 DropdownMenu.MainWindow..ctor() 在 D:\ComPany\xxx\dotnet\wpf\StudayAdonisUI\DropdownMenu\MainWindow.xaml.cs 中:61

修改前代码

在这里插入图片描述

问题讲解

我们仔细去看错误信息会发现有这样一句如下
在这里插入图片描述
这里明显是说我们的连接时这个 版本不受支持,可以去掉版本设置

修改后代码

    public void InintialDB()         
    {             
       string path =   AppDomain.CurrentDomain.SetupInformation.ApplicationBase  + "userSqlite.db";             
       if (!File.Exists(path))             
          {                 
            File.Create(path).Close();             
          }             
     ConnectionConfig connectionConfig = new ConnectionConfig(); 
     connectionConfig.DbType = DbType.Sqlite;   
     connectionConfig.IsAutoCloseConnection = true;             
     //自动释放数据务,如果存在事务,在事务结束后释放
     connectionConfig.InitKeyType = InitKeyType.Attribute;  
     connectionConfig.ConnectionString = $"Data Source={path}"; 
     using (SqlSugarClient sugarClient = new 
     SqlSugarClient(connectionConfig)) 
        {
         sugarClient.DbFirst.CreateClassFile(@"D:\代码生成\后端\dotnet\dbModels\");   
                  
        }          
     }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值