我正在尝试使用以下方法将连接字符串从json文件获取到DAL类库:
private static IConfigurationRoot config;
private static string connectionString;
public UserDAL()
{
config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
connectionString = config.GetConnectionString("DefaultString");
}
在json文件中:
{
"ConnectionStrings": {
"DefaultString": "theconnectionstring"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
当我尝试打开连接时发生错误,因此con.Open();