Reputation: 789
I'm new to Asp.Net MVC. My question is how to change DefaultConnection in the web.config file to use my entity framework connection string. my goal is one database in whole application.
I'm using Asp.Net MVC 5, and entity framework database first. the other posts I found here, doesn't specify my problem correctly.
Just tell me if I have to bring more information. Thanks.
Upvotes: 7
Views: 6629
Reputation: 43
Find your AccountModels.cs/vb file and change
public class UsersContext : DbContext
{
public UsersContext()
: base("TestEntities")
{
}
...
}
I'm not sure if MVC 5 does the same initial file structure as MVC3- if so find in Filters folder InitializeSimpleMembershipAttribute.cs/vb file
private class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
Database.SetInitializer<UsersContext>(null);
try
{
...
//change this
WebSecurity.InitializeDatabaseConnection("TestEntities", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}...
}
If those files aren't present. Do Ctrl+F and search ~Entire Project for DefaultConnection and replace it with your desired connection string from Webconfig
Upvotes: 1
Reputation: 1742
In you IdentityModels you should change the connectionString name:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
Change the DefaultConnection to your testEntities.
Upvotes: 9