Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to configure connection string in MVC 6 in ASP.NET vNext

$
0
0

Hi,

I have created one MVC application in MVC 6 framework in ASP.NET vNext. In my application i am reading database table using Entity Framework,but the connection string which

is present in config.json file,that connection string is not readable in my application,and hence i am not able to get the data from my database table.

The Exception which i am getting is :- "No data stores are configured. Configure a data store using OnConfiguring or by creating an ImmutableDbContextOptions with a data store configured and passing it to the context."

My config.json file is:-

{
"Data": {
"DefaultConnection": {
"EmployeeContext": "Server= .;Database=Manish_Database;Trusted_Connection=True;MultipleActiveResultSets=true"
                              }
            }
}

and Startup.cs file is:-

public void Configure(IBuilder app)
{

// Setup configuration sources
var configuration = new Configuration();
configuration.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();

// Set up application services
app.UseServices(services =>
{
// Add EF services to the services container
services.AddEntityFramework()
.AddSqlServer();

// Configure DbContext
services.SetupOptions<DbContextOptions>(options =>
{
options.UseSqlServer(configuration.Get("Data:DefaultConnection:EmployeeContext"));
});

// Add Identity services to the services container
services.AddIdentity<ApplicationUser>()
.AddEntityFramework<ApplicationUser, ApplicationDbContext>()
.AddHttpSignIn();

// Add MVC services to the services container
services.AddMvc();
});

// Enable Browser Link support
app.UseBrowserLink();

// Add static files to the request pipeline
app.UseStaticFiles();

// Add cookie-based authentication to the request pipeline
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Home/Details"),
});

 


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>