How to override local connection string with azure connection string at runtime? [duplicate]

假如想象 提交于 2019-12-13 11:28:25

问题


I have written connection string in appsettings.json for .Net core project. My connection string is :

 "ConnectionStrings": {
"OT_DB_Connection": "Data Source=108.***.**.**;Initial Catalog=O*******s;User ID=O*******s;Password=O*********$"

},

I am accessing this connection string in startup.cs file as shown below.

options.UseSqlServer(Configuration.GetConnectionString("OT_DB_Connection"));

Now i deployed this website on azure and i have separate database on azure and i want that my website will to connect to azure database at runtime by overriding the local connection string.

Please suggest how i can achieve this.

Thanks


回答1:


You may create application setting entry (in Azure) with name ConnectionStrings:OT_DB_Connection and read it as

Configuration["ConnectionStrings:OT_DB_Connection"]

This code will read both and you appsettings value for local development, and overrided value in Azure App Service.



来源:https://stackoverflow.com/questions/52050417/how-to-override-local-connection-string-with-azure-connection-string-at-runtime

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