My connection string seems to be null, not sure how to get it to reference it correctly.
My connection string in appsettings:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DevConnection": "Data Source=xyz;Initial Catalog=xyz;User ID=xyz Password=xyz"
}
}
Then I am using:
private readonly string connString = System.Configuration.ConfigurationManager.AppSettings["DevConnection"];
SqlConnection conn = new SqlConnection(connString);
var command = new SqlCommand(GetReadQuery(), conn);
conn.Open();
But get The ConnectionString property has not been initialized.
In debug mode connString = null but not sure why it's not getting the string.
Thanks