Is this how to set Context Connection String Using CloudConfigurationManager?

删除回忆录丶 提交于 2019-12-04 23:45:50
knightpfhor

There is not a more elegant solution at the moment, no. In fact this is quite a bit more elegant than what you would have had to have written a month ago. The CloudConfigurationManager is a class that is new in the 1.7 SDK and was created because previously there was no built in support for doing this sort of thing. If you wanted to do what CloudConfigurationMangager does now you had to create your own class, which was pretty common.

Would you be able to post a sample of the code?

CloudConfigurationManager should first check if the code is executing in a Windows Azure role, and if so, attempt to retrieve the configuration value from the in the ServiceConfiguration.cscfg file (that is deployed with the role). If not running in a role, CloudConfigurationManager should revert to the application's .config (web.config or app.config) file. In either case, I believe NULL is returned if the value is not found.

With the connection string retrieve from the .cscfg file (assuming the code is running in a Windows Azure web role), the value could be passed to an EF constructor overload which would set the connection string.

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