.net core 3.1 使用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\");
}
}