如何部署ASP.NET网站当你处理连接字符串? [英] How do you deal with connection strings when deploying an ASP.NET site?

查看:176
本文介绍了如何部署ASP.NET网站当你处理连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我们的测试和生产数据库在同一台服务器上,但不同的名称。部署意味着编辑Web.config文件改变所有正确的数据库连接字符串。一个步骤,我忘了所有过于频繁......

Right now our test and production databases are on the same server, but with different names. Deploying has meant editing Web.config to change all the connection strings for the correct database. A step which I forget all too frequently...

我们已经创建了最终测试一个新的数据库服务器,我在移动数据库......但现在的服务器将是不同的,我们仍然需要处理的连接字符串的问题。

We've finally created a new database server for testing, and I'm moving the databases over... but now the server will be different and we'll still need to deal with connection string issues.

我想通过一个hosts文件管理它,但开关,我的台式机上,每当我需要测试对生产数据的想法似乎很麻烦的最好的。

I was thinking of managing it via a hosts file, but the thought of switching that on my desktop machine whenever I need to test against production data seems cumbersome at best.

所以,我只是想知道是否有出有更好的办法。东西会建立一个生产的web配置部署将是理想...

So I'm just wondering if there's a better way out there. Something that would build with a "production" web config for deployment would be ideal...

推荐答案

使用一个<一个href=\"http://weblogs.asp.net/scottgu/archive/2008/01/28/vs-2008-web-deployment-project-support-released.aspx\"相对=nofollow> Web部署项目并更新wdproj文件(这只是一个MSBuild文件)与一些后生成任务输出正确的config文件。我把一个web.config和web.release.config然后在wdproj文件中使用这样的:

Use a Web Deployment Project and update the wdproj file (it's just an MSBuild file) with some post build tasks to output the correct .config file. I keep a web.config and web.release.config then use this in the wdproj file:

<Target Name="AfterBuild">
    <Copy Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " SourceFiles="$(SourceWebPhysicalPath)\web.release.config" DestinationFiles="$(OutputPath)\web.config" />
    <Delete Files="$(OutputPath)\web.release.config" />
</Target>

更多信息

有一个简单的解决方案有的喜欢用<一个href=\"http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx\"相对=nofollow>的appSettings和是connectionStrings的configSource属性,然后再从不覆盖生产服务器上的文件。

A simpler solution some like is using configSource property of appSettings and connectionStrings and then never overwriting that file on the production server.

这篇关于如何部署ASP.NET网站当你处理连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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