Hari Krishna

Hari Krishna

  • 1.5k
  • 129
  • 45.9k

connection string issue in web api core with ado.net

Aug 10 2023 11:40 AM

Hi,
I am new to web api core,I have created one web api core with ado.net application.
I have declared a conenction string in appseeting.json,
I am trying new access in the controller but i am getting null value?
can any one help me how to access conenction string in controller from appsetting.sjon
step1 
appsettins.json
{
  "Logging": {

    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }

  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\MSSQLLOCALDB;Database=resource;Trusted_Connection=True;"

  }
}

step 2
 SqlConnection con1 = new SqlConnection(configuration.GetConnectionString("DefaultConnection"));


Answers (8)