如何在单个连接(Asp.Net)Sql Server上设置多个数据库? [英] How Do I Set Multiple Database On A Single Connection (Asp.Net) Sql Server ?

查看:116
本文介绍了如何在单个连接(Asp.Net)Sql Server上设置多个数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<add name="HelpdeskConString" connectionString="Data Source=.;Initial Catalog=CasDB;Integrated Security=True"/>







<add name="HelpdeskConString" connectionString="Data Source=.;Initial Catalog=HelpDB;Integrated Security=True"/>







我的网络项目中有两个数据库两个子项目我们想在web配置中同时使用两个数据库..



如何在这种情况下设置条件..?




I have two database in my web projct its containg two sub project we wanted two use both database in web config..

how to set condition in this situation..?

推荐答案

在Web配置中,不能有两个具有相同名称(键)的不同数据库连接字符串。



但是,您可以拥有两个具有相同属性和不同连接字符串的不同类。通过这种方式,根据您的条件,您可以调用适当的类和相应的数据库。



您需要举例说明您的方案,以便人们可以提出不同的想法。



希望这会有所帮助。
You can not have two different database connection strings with the same name (key) in the web config.

However, you can have two different classes with the same property and different connection strings. In this way, based on your condition, you can call appropriate class and respective database.

You need to give an example of your scenario so that people can suggest different ideas.

Hope this helps.


名称应该不同





Name should be Different


<add name="ConString1" connectionstring="Data Source=.;Initial Catalog=CasDB;Integrated Security=True" />







<add name="Constring2" connectionstring="Data Source=.;Initial Catalog=HelpDB;Integrated Security=True" />


您可以使用多个连接字符串,只需在代码隐藏时给出您想要连接的名称.. :)



You can use multiple connection string like that just give name at codebehind what ever connection you eant touse.. :)

<connectionstrings>
   <add name="Connection1" providername="System.Data.SqlClient" connectionstring="Data Source=Server Name;Initial Catalog=Database1;User ID=Usename;Password=****" />
   <add name="Connection2" providername="System.Data.SqlClient" connectionstring="Data Source=Server Name;Initial Catalog=Database2;User ID=Usename;Password=****" />
 </connectionstrings>


这篇关于如何在单个连接(Asp.Net)Sql Server上设置多个数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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