本文介绍了不同Web服务器的不同连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET 2.0中是否有一种方法可以在基于服务器动态使用的web.config文件中具有不同的连接字符串设置



Web应用程序正在运行?


例如,您有两个测试Web服务器(TEST1和TEST2)和一个

生产Web服务器(PROD1)。每个连接到不同的

数据库,用于一般数据访问和会员/角色提供者。


< connectionStrings>

< add name =" Test1DB" connectionString =" Data Source = Test1DBServer; Initial

Catalog = MyApp; User Id = User; Password = password;" />

< add name =" Test2DB" connectionString =" Data Source = Test2DBServer; Initial

Catalog = MyApp; User Id = User; Password = password;" />

< add name =" Prod1DB" connectionString =" Data Source = Prod1DBServer; Initial

Catalog = MyApp; User Id = User; Password = password;" />

< / connectionStrings>


....


< providers>

< add name =" CustomizedMembershipProvider"

type =" System.Web.Security.SqlMembershipProvider"

connectionStringName =" Prod1DB"

applicationName =" MyApp"

minRequiredPasswordLength =" 5"

minRequiredNonalphanumericCharacters =" 0" />

< / providers>

如果此应用程序在我的生产服务器(PROD1)上运行,那么一切都很好

,因为提供程序设置为使用Prod1DB连接字符串。但是,如果

应用程序在我的TEST1 Web服务器上运行,我该如何以编程方式将
更改connectionStringName设置更改为Test1DB连接字符串?


谢谢,


-

Pat B

BCC Software,Inc

AB ?? WE BELL + HOWELL COMPANY

解决方案



是的 - 查看System.Environment.MachineName,并相应地命名各种

连接字符串...


或者,看看:



-

Mark Rae

ASP.NET MVP





是的 - 查看System.Environment.MachineName,并相应地命名各种

连接字符串...


或者,看看:



-

Mark Rae

ASP.NET MVP





OK。



啊 - 我必须承认,如果没有一些我自己试验的话我不知道 - 我从来没有使用任何会员资格......


然而,Web部署项目肯定*会为你做这件事,因为

它允许不同的构建来替换各个部分web.config

文件......

-

Mark Rae

ASP.NET MVP



Is there a way in ASP.NET 2.0 to have different connection strings settings
in a web.config files that are dynamically used based upon the server that
the web application is running on?

For example, you have have two test web servers (TEST1 and TEST2) and a
production web server (PROD1). Each of these connection to a different
database for general data access and for membership/role providers.

<connectionStrings>
<add name="Test1DB" connectionString="Data Source=Test1DBServer;Initial
Catalog=MyApp;User Id=User;Password=password;" />
<add name="Test2DB" connectionString="Data Source=Test2DBServer;Initial
Catalog=MyApp;User Id=User;Password=password;" />
<add name="Prod1DB" connectionString="Data Source=Prod1DBServer;Initial
Catalog=MyApp;User Id=User;Password=password;" />
</connectionStrings>

....

<providers>
<add name="CustomizedMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="Prod1DB"
applicationName="MyApp"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0" />
</providers>

If this application is running on my production server (PROD1) all is well
as the provider is set to use the Prod1DB connection string. However, if the
application is running on my TEST1 web server, how do I programmatically
change the connectionStringName setting to the Test1DB connection string?

Thanks,

--
Pat B
BCC Software, Inc
A B??WE BELL + HOWELL COMPANY

解决方案

Yep - have a look at System.Environment.MachineName, and name your various
connection strings accordingly...

Alternatively, have a look at:
http://msdn2.microsoft.com/en-us/asp.net/aa336619.aspx

--
Mark Rae
ASP.NET MVP
http://www.markrae.net



Yep - have a look at System.Environment.MachineName, and name your various
connection strings accordingly...

Alternatively, have a look at:
http://msdn2.microsoft.com/en-us/asp.net/aa336619.aspx

--
Mark Rae
ASP.NET MVP
http://www.markrae.net


OK.

Ah - I have to confess that I don''t know for certain without some
experimenting of my own - I never use any of the Membership stuff...

However, Web Deployment Projects would *certainly* do this for you because
it allows different builds to replace various sections of the web.config
file...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


这篇关于不同Web服务器的不同连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 23:07
查看更多