entity-frameworkdatabase-first

Is there a way to change connection string in database first?


I have several databases, the schema of them are same. When I use database-first, the connection string is specified when I create the edmx file. I want to know, is there a way to change the connection string? This is, so I can choose which database to operate.


Solution

  • Change the connection string in the web.config file.

      <connectionStrings>
        <add name="SandBoxEntities" connectionString="metadata=r... />
      </connectionStrings>
    

    I abbreviated the actual connection string because it isn't important -- just wanted to give you an idea of what to look for in the web.config file.

    You can also change your connection strings programatically. Check out Example 16.2. Programmatically modifying an EntityConnectionString.