1
我一直在嘗試使用Visual Studio代碼連接Ms SQL服務器和MVC核心應用程序。 到目前爲止,我已經添加什麼是連接MVC核心應用程序到MS SQL服務器的步驟
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<MvcMovieContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
在startup.cs文件
和
"ConnectionStrings": {
"MvcMovieContext": "(Server=localdb)\\mssqllocaldb;Database=MvcMovieContext-20613a4b-deb5-4145-b6cc-a5fd19afda13;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Data": {
"DefaultConnection": {
"ConnectionString": "MvcMovieContext"
}
}
在appsettings.json文件。
我得到一個錯誤
值不能爲null.Parameter名稱:ConnectionString的
需要幫助。你能否請我的問題upvote,因爲我被阻止提出更多的問題,因爲投票少,意見少。我只問了7個問題。他們都沒有被低估。我必須擺脫這個禁令。任何建議都會有很大的幫助 –