TAW*_*AWH 5 c# asp.net-core-2.0
我在我的电脑上使用 ASP.NET Core 2.0、Visual Studio 2017 Enterprise、版本 15.5.4 和本地数据库。
我是第一次使用数据库,遇到了以下问题:
处理请求时发生未处理的异常。
ArgumentNullException:值不能为空。
参数名称:连接字符串。
在阅读并尝试了所有可能的建议以及可能的解决方案后,问题仍然存在。
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<VideosContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
{
"ConnectionString": {
"DefaultConnection": "Server =(localdb)\\mssqllocaldb;Database=Videos;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?预先感谢您的任何建议。
您的应用程序设置 JSON 文件的语法是否正确?
{
"ConnectionStrings": {
"DefaultConnection": "Server =(localdb)\\mssqllocaldb;Database=Videos;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8442 次 |
| 最近记录: |