I'm developing a test Project using asp.net core. For Connecting to database I'm using Entity framework. I add appsetings.json file to the project and change the connection string as follows:
{
"ConnectionStrings": {
"DefaultConnection": "Server=.\\mihanrayan;Initial Catalog=SportsStore;User = sa; Password = 123456"
}
}
sql version is : mssql 2008 r2
in startup.cs class I add codes below:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration["Data:SportStoreProducts:ConnectionString"]));
services.AddTransient<IProductRepository, EFProductRepository>();
}
but
options.UseSqlServer(
Configuration["Data:SportStoreProducts:ConnectionString"]));
returns this error:
An exception of type 'System.ArgumentNullException' occurred in Microsoft.EntityFrameworkCore.SqlServer.dll but was not handled in user code
Additional information: Value cannot be null.
Data:SportStoreProducts:ConnectionString
would resolve to that location within the JSON?