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

杀马特。学长 韩版系。学妹 提交于 2019-11-30 05:28:34

问题


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.


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/15153666/using-a-separate-file-to-maintain-the-connection-string-for-entity-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!