Home > Software engineering >  InvalidOperationException: Connection string not found
InvalidOperationException: Connection string not found

Time:05-01

I am trying to run my ASP.NET Core MVC application but when I do, I get this error:

options.UseSqlServer(builder.Configuration.GetConnectionString("Farah_O_Exercise_4Context") ?? throw new InvalidOperationException("Connection string 'Farah_O_Exercise_4Context' not found.")));

Here is the result after clicking a page on the app

CodePudding user response:

you have to add your connection string in appsettings.json:

"ConnectionStrings": {
"Farah_O_Exercise_4Context": "Server=(localdb)\\mssqllocaldb;Database=yourDbName;Trusted_Connection=True;MultipleActiveResultSets=true"}

Hope this help you! Have a nice day :)

  • Related