如何在运行时使用天蓝色的连接字符串覆盖本地连接字符串? [英] How to override local connection string with azure connection string at runtime?

查看:87
本文介绍了如何在运行时使用天蓝色的连接字符串覆盖本地连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.net核心项目的appsettings.json中编写了连接字符串.我的连接字符串是:

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*********$"

},

我正在如下所示访问startup.cs文件中的此连接字符串.

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

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

现在我将该网站部署在azure上,并且在azure上有一个单独的数据库,我希望我的网站将通过覆盖本地连接字符串在运行时连接到azure数据库.

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.

谢谢

推荐答案

您可以创建名称为ConnectionStrings:OT_DB_Connection的应用程序设置条目(在Azure中)并将其读取为

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

Configuration["ConnectionStrings:OT_DB_Connection"]

此代码将同时读取您为本地开发的appsettings值和Azure App Service中的覆盖值.

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

这篇关于如何在运行时使用天蓝色的连接字符串覆盖本地连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆