轻松地将ConnectionString切换为发布到Azure [英] Easily switching ConnectionStrings on publish to Azure

查看:70
本文介绍了轻松地将ConnectionString切换为发布到Azure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在建立一个Azure Web角色。我正在针对 localhost 上的本地数据库服务器测试该项目。然后,当确信该项目正在运行时,我将其发布到Windows Azure上的暂存。

I'm currently building an Azure Web Role. I am testing this project against a local database server on localhost. Then, when confident that the project is working, I publish it to Staging on Windows Azure.

但是,我还必须记住更改连接字符串以指向在部署之前先在SQL Azure上运行实时SQL Server,然后再将其更改回 localhost

However, I also have to remember to change the connection string to point to the live SQL server on SQL Azure before deploying, and then change it back to localhost afterwards.

有什么不错的选择吗?自动执行此操作的方法,或者完全避免该问题采取的其他方法?例如,有没有一种方法可以使Azure的配置文件不会在每次部署时都更新?

Is there any nice way to automate this, or perhaps a different process to take to avoid the issue altogether? For example is there a way to have a configuration file for Azure that isn't updated with every deploy?

推荐答案

仅引用计算机名称以及是否使用Azure,就动态地切换相应引用的ConnectionString。

I ended up just referencing the machine name and whether or not I was using Azure, dynamically switching the ConnectionString I referenced accordingly.

这篇关于轻松地将ConnectionString切换为发布到Azure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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