InvalidOperationException:未找到连接字符串

InvalidOperationException: Connection string not found

我正在尝试 运行 我的 ASP.NET 核心 MVC 应用程序,但是当我这样做时,我收到此错误:

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

您必须在 appsettings.json 中添加您的连接字符串:

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

希望对您有所帮助! 祝你有美好的一天:)