简体   繁体   English

.net服务-如何在web.config中设置多个数据库

[英].net service - how to set more than 1 database in web.config

I've created a .net service that work with a database declared in web.config file. 我创建了一个.net服务,该服务可与web.config文件中声明的数据库一起使用。 Now the project evolved and i need to query more than 1 database, how can i do this in web.config and then specify the database i want to query in the c# files?. 现在该项目已发展,我需要查询多个数据库,如何在web.config中执行此操作,然后在c#文件中指定要查询的数据库? Here's how the current database is specified: 这是指定当前数据库的方式:

<connectionStrings>
    <add name="stringName" connectionString="Data Source=XXXXXXXXX;Initial Catalog=DBName;Persist Security Info=True;User ID=UsrID;Password=bazinga;Application Name=AppName;Connect Timeout=20" providerName="System.Data.SqlClient"/>
  </connectionStrings>

Thanks! 谢谢!

You just add another item to the connectionStrings section with a different name specification. 您只需将另一个项目添加到具有不同名称说明的connectionStrings部分。

How your program calls the database is another story and I do not have the section of code which is defining the existing one. 您的程序如何调用数据库是另外一回事了,我没有定义现有代码的那一部分代码。 You would just need to find that and use the same method, just adding another variable to identify it. 您只需要查找并使用相同的方法,只需添加另一个变量即可对其进行标识。

<connectionStrings>
    <add name="stringName" connectionString="Data Source=XXXXXXXXX;Initial Catalog=DBName;Persist Security Info=True;User ID=UsrID;Password=bazinga;Application Name=AppName;Connect Timeout=20" providerName="System.Data.SqlClient"/>
    <add name="stringName2" connectionString="Data Source=XXXXXXXXX;Initial Catalog=DBName;Persist Security Info=True;User ID=UsrID;Password=bazinga;Application Name=AppName;Connect Timeout=20" providerName="System.Data.SqlClient"/>
</connectionStrings>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM