问题
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