2

I have an ASP.NET MVC 4 web app and I'm defining connection strings in my web.config. I'm using SimpleMembership which by default wants to use a connection string with the name DefaultConnection

I'm also using EntityFramework 5 to access the same database and store my app data. My EntityFramework context is called AppContext. Therefore, my context wants to by default use a connection string with the name AppContext.

My current solution is to define two connection strings:

<add name="DefaultConnection" connectionString="REMOVED" providerName="System.Data.SqlClient" />
<add name="AppContext" connectionString="REMOVED" providerName="System.Data.SqlClient" />

What's the commonly used solution here? I assume this is a common scenario and people are either overriding the default name of the EntityFramework connection string or the SimpleMembership connection string.

Elijah W. Gagne
  • 2,801
  • 4
  • 31
  • 29

1 Answers1

0

Hum, my turn to have a question: who is the boss ? :-)

You don't have to accept the default settings, unless they really matches what YOU WANT to do.

I don't see why you would need to have 2 exactly identical connection string to the same database! I am sure it can work that way, but it's not a big deal to make either one use the other connection string. For example, by default in AccountModels, I have:

public class UsersContext : DbContext
{
    public UsersContext()
        : base("DefaultConnection")
    {
    }

    public DbSet<UserProfile> UserProfiles { get; set; }
    public DbSet<webpages_Membership> Membership { get; set; }
}

I just need to change "DefaultConnection" to "AppContext" in there to have SimpleMembership using the same connection string than Entity Framework:

public class UsersContext : DbContext
{
    public UsersContext()
        : base("AppContext")
    {
    }

    public DbSet<UserProfile> UserProfiles { get; set; }
    public DbSet<webpages_Membership> Membership { get; set; }
}
BernardG
  • 1,956
  • 3
  • 17
  • 25