1

So I have been going around stackoverflow and checking all the issues relating to my problem and everything checks out but I'm still getting the same error.

Value cannot be null. Parameter name: connectionString

Is the result when I run my add-migration "Initial Migration".

here is my code at Startup.cs

public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddDbContext<LibraryContext>(options 
            => options.UseSqlServer(Configuration.GetConnectionString("LibraryConnection")));
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseBrowserLink();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }

and here is my connectionstring at appsettings.json

{
 "ConnectionString": {
   "LibraryConnection": "Server(localdb)\\MSSQLLocalDB;Database=Library_Dev;Trusted_Connection=True;MultipleActiveResultSets=true"
},
   "Logging": {
     "IncludeScopes": false,
     "LogLevel": {
       "Default": "Warning"
     }
   }
}

note that I have a LibraryData project (which is another project) and the class consist of a class called LibraryContext

public class : DbContext
{
    public LibraryContext(DbContextOptions options) : base(options) { }

    public DbSet<Patron> Patrons { get; set; }
}   

I can't seem to find what am I doing wrong as I have done everything according to the materials and questions online! can anyone help me out on this?

1 Answer 1

7

I think you've made a typo in your appsettings.json ConnectionString should be ConnectionStrings

{
 "ConnectionStrings": {
   "LibraryConnection": "Server(localdb)\\MSSQLLocalDB;Database=Library_Dev;Trusted_Connection=True;MultipleActiveResultSets=true"
},
   "Logging": {
     "IncludeScopes": false,
     "LogLevel": {
       "Default": "Warning"
     }
   }
}

Sign up to request clarification or add additional context in comments.

1 Comment

I am not sure how you saw that! You are my hero dude. Thank you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.