根据请求种类选择连接字符串 [英] Choosing a Connection String based on kind of request

查看:60
本文介绍了根据请求种类选择连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经有一个Web服务,客户端可以通过它执行数据库操作,而网站可以读取数据库。

I used to have a web service through which a client could perform DB operations and a website could read the DB.

现在,由于重新设计的需要,通过Web服务,客户端可以进行数据库操作。该数据库位于工作站A中。网站通过相同的Web服务从数据库中检索信息。该数据库位于工作站B中。

Now, due to re-design needs, through the webservice a client can make DB operations. This DB is in workstation A. Through the same webservice, a website retrieves information from DB. This DB is in workstation B.

位置A中的数据库不断向工作站B中的数据库提供数据,我需要网站在工作站B上显示信息。

DB in location A constantly feeds the DB in workstation B, and I need the website to display the information on workstation B.

有什么办法可以使web.config上具有不同的连接字符串(Web服务和网站共享相同的配置文件),并让Webservice使用相应的连接字符串,具体取决于是客户请求还是网站请求?

Is there any way I can have different connection strings on the web.config (both the web service and the website share the same config file) and have the webservice use the corresponding one depending on whether its a client request or a website request ?

推荐答案

是否使用

HttpContext.Current != null? ConnectionStrings["Website"].ConnectionString : ConnectionStrings["Client"].ConnectionString

,它非常完美

这篇关于根据请求种类选择连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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