I'm using ASP.NET Core 2.0, Visual Studio 2017 Enterprise, Version 15.5.4 and a local DB on my PC.
I'm working for the first time with database first and I have encountered the following problem:
unhandled exception occurred while processing the request.
ArgumentNullException: Value cannot be null.
Parameter name: connectionString.
The problem remains after reading and trying every possible suggestions along with possible solutions.
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(); 
What am I doing wrong? Thank you in advance for any suggestion.
Does your app settings JSON file have the correct syntax?
{
    "ConnectionStrings": {
        "DefaultConnection": "Server =(localdb)\\mssqllocaldb;Database=Videos;Trusted_Connection=True;MultipleActiveResultSets=true"
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With