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

后端 未结 2 1721
情话喂你
情话喂你 2021-01-05 14:01

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.

相关标签:
2条回答
  • 2021-01-05 14:36

    In case anyone stumbles upon this question. You can put the connection strings in a separate config file using configSource but DONT expect the EF designer to work happily with it.

    Every time to go to edit the edmx and 'Update from Database' it will ask for a new connection string and then always want to save it back to the web.config. Not ideal and for me not workable. This is the case in EF6 and previous.

    0 讨论(0)
  • 2021-01-05 14:49

    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>
    
    0 讨论(0)
提交回复
热议问题