管理调试和释放连接字符串 [英] Managing A Debug and Release Connection String

查看:269
本文介绍了管理调试和释放连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一个很好的方法来管理一个调试和在.NET / SQLServer的应用程序中释放连接字符串?

What is a good approach to managing a debug and release connection string in a .NET / SQLServer application?

我有两个SQL服务器,生产和构建/调试,我需要的时候我的ASP.NET应用程序部署在两者之间切换的方法。

I have two SQL Servers, a production and a build/debug and I need a method of switching between the two when my ASP.NET application is deployed.

目前我只是将它们存储在web.config和评论一个或其他的,但是当部署是容易出错。

Currently I simply store them in the web.config and comment one or the other out, however that is error prone when deploying.

推荐答案

创建调试和发布Web.config文件的版本,例如Web.debug.config和Web.release.config。然后添加一个pre-编译条件复制相应版本到基于当前目标的web.config文件。

Create a Debug and Release version of the Web.config file, e.g. Web.debug.config and Web.release.config. Then add a pre-compile condition that copies the relevant version into the web.config based upon the current Target.

编辑::要添加pre编译状态右键点击你的项目,选择属性,然后转到这个生成事件选项卡,并添加以下到$的code p $ pcompile条件。很明显,你将不得不ammend的code你的需求,参见下图。

To add the pre compile condition right click on you project and select "Properties" then goto the "Build Events" tab and add the code below to the precompile condition. Obviously, you will have to ammend the code to your needs, see image below.

@echo off

echo Configuring web.config pre-build event ...

if exist "$(ProjectDir)web.config" del /F / Q "$(ProjectDir)web.config"

if "$(ConfigurationName)" == "Debug Test" goto test
if "$(ConfigurationName)" == "Debug M" goto M
if "$(ConfigurationName)" == "Debug BA" goto BA
if "$(ConfigurationName)" == "Release Test" goto test
if "$(ConfigurationName)" == "Release M" goto M
if "$(ConfigurationName)" == "Release BA" goto BA

echo No web.config found for configuration $(ConfigurationName). Abort batch.
exit -1
goto :end

:test
copy /Y "$(ProjectDir)web.config.test" "$(ProjectDir)web.config"
GOTO end

:BA
copy /Y "$(ProjectDir)web.config.BA" "$(ProjectDir)web.config"
GOTO end

:M
copy /Y "$(ProjectDir)web.config.M" "$(ProjectDir)web.config"
GOTO end

:end
echo Pre-build event finished

这篇关于管理调试和释放连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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