Search code examples
entity-frameworkentity-framework-4connection-string

Using a separate file to maintain the connection string for entity framework


I have my connection string currently in my web.config file.

Is it possible to place it in a separate file and point entity framework to it.


Solution

  • I found the answer here Separate ConnectionStrings and mailSettings from web.config? Possible?:

    <configuration>
        <connectionStrings configSource="connections.config"/> 
    </configuration>
    

    With file connections.config containing

    <connectionStrings>
       <add name="name" connectionString="conn_string" providerName="System.Data.SqlClient" />
       <add name="name2" connectionString="conn_string2" providerName="System.Data.SqlClient" />
    </connectionStrings>