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.
In you IdentityModels you should change the connectionString name:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
Change the DefaultConnection to your testEntities.
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
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