不同Web服务器的不同连接字符串

编程入门 行业动态 更新时间:2024-10-23 10:26:44
本文介绍了不同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

解决方案

" PatB" < Pa ** @ community.nospamwrote in message news:D5 **************************** ****** @ microsof t ...

ASP.NET 2.0中是否有一种方法可以使用不同的连接字符串 设置 在web.config文件中,这些文件是根据运行Web应用程序的服务器动态使用的?

是的 - 查看System.Environment.MachineName,并相应地命名各种 连接字符串... 或者,看看: msdn2.microsoft/en-us/asp/aa336619.aspx - Mark Rae ASP.NET MVP http: //www.markrae

Mark, 我和你完全一样在ASP.NET 1.1中通过使用机器名称引用我的 连接字符串名称来说明。然后在Application_Start 方法中,我将连接字符串变量设置为来自web.config文件的相应连接 字符串。 这适用于我将在我的代码中用于 数据访问的连接字符串。 但是对于成员资格/角色呢在web.config文件中指定 connectionStringName的提供程序。我可以在Application_Start方法中动态地改变提供者的connectionStringName吗? 如果是这样,我该怎么做? (尝试但无法弄明白)。 请原谅我对ASP.NET 2.0缺乏了解。这是我第一次尝试 使用ASP.NET 2.0。 谢谢, - - Pat B BCC Software,Inc AB ?? WE BELL + HOWELL COMPANY " Mark Rae [MVP]"写道:

" PatB" < Pa ** @ community.nospamwrote in message news:D5 **************************** ****** @ microsof t ...

ASP.NET 2.0中是否有一种方法可以使用不同的连接字符串 设置 在web.config文件中,这些文件是根据运行Web应用程序的服务器动态使用的?

是的 - 查看System.Environment.MachineName,并相应地命名各种 连接字符串... 或者,看看: msdn2.microsoft/en-us/asp/aa336619.aspx - Mark Rae ASP.NET MVP http: //www.markrae

" PatB" < Pa ** @ community.nospamwrote in message news:6D **************************** ****** @ microsof t ...

我完全按照你在ASP.NET 1.1中所说的那样,通过引用我的 连接字符串名称与机器名称。然后在 Application_Start 方法中,我将连接字符串变量设置为来自web.config文件的相应连接 字符串。 这对我在代码中用于 数据访问的连接字符串很有用。

OK。

但对于会员/角色提供商而言, connectionStringName在web.config文件中指定。我可以动态地支付 在Application_Start 方法中更改提供者的connectionStringName吗? 如果是这样的话我这样做? (尝试但无法弄清楚)。

啊 - 我必须承认,如果没有一些我自己试验的话我不知道 - 我从来没有使用任何会员资格...... 然而,Web部署项目肯定*会为你做这件事,因为 它允许不同的构建来替换各个部分web.config 文件...... - Mark Rae ASP.NET MVP www.markrae

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

解决方案

"PatB" <Pa**@community.nospamwrote in message news:D5**********************************@microsof t...

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?

Yep - have a look at System.Environment.MachineName, and name your various connection strings accordingly... Alternatively, have a look at: msdn2.microsoft/en-us/asp/aa336619.aspx -- Mark Rae ASP.NET MVP www.markrae

Mark, I have done exactly as you stated in ASP.NET 1.1 by preferencing my connection string names with the machine name. Then in the Application_Start method I set a connection string variable to the appropriate connection string from the web.config file. This works great for a connection string that I am going to be using for data access within my code. But what about for the membership/role providers where the connectionStringName is specified in the web.config file. Can I dynamically change the provider''s connectionStringName in the Application_Start method? If so how do I do that? (tried but couldn''t figure it out). Please pardon my lack of knowledge with ASP.NET 2.0. It''s my first attempt at using ASP.NET 2.0. Thank you, -- Pat B BCC Software, Inc A B??WE BELL + HOWELL COMPANY "Mark Rae [MVP]" wrote:

"PatB" <Pa**@community.nospamwrote in message news:D5**********************************@microsof t...

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?

Yep - have a look at System.Environment.MachineName, and name your various connection strings accordingly... Alternatively, have a look at: msdn2.microsoft/en-us/asp/aa336619.aspx -- Mark Rae ASP.NET MVP www.markrae

"PatB" <Pa**@community.nospamwrote in message news:6D**********************************@microsof t...

I have done exactly as you stated in ASP.NET 1.1 by preferencing my connection string names with the machine name. Then in the Application_Start method I set a connection string variable to the appropriate connection string from the web.config file. This works great for a connection string that I am going to be using for data access within my code.

OK.

But what about for the membership/role providers where the connectionStringName is specified in the web.config file. Can I dynamically change the provider''s connectionStringName in the Application_Start method? If so how do I do that? (tried but couldn''t figure it out).

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 www.markrae

更多推荐

不同Web服务器的不同连接字符串

本文发布于:2023-10-30 22:44:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   服务器   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!