[Solved] ASP.Net Core MVC Error: The ConnectionString property has not been initialized

on Nov 17, 2021 05:48 AM

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);

But get The ConnectionString property has not been initialized.

In debug mode connString = null but not sure why it's not getting the string.


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Nov 17, 2021 06:07 AM