Click here to Skip to main content
13,093,097 members (68,931 online)
Rate this:
Please Sign up or sign in to vote.
Hi Friends,

am creating a Web application. In this i want to use 2 Sqlserver databases.

I have two databases in Sqlserver2005 as StudentDB and CollegeDB. NOW i want to use these 2 databases in my program.

so how should i use, and how to store these two databases in web.configfile.

Please help.

I want to use 2 databases with one Asp.Net Application.

Please Help THANKS.
Posted 11-Jan-13 20:28pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

As already suggested you can store two different connection strings and then you can open two separate SqlConnection objects, on per each database.

However, to give you an alternative, you can also define a linked server in either of the Sql Server instances. Using linked server you can achieve a situation where you connect only to one database server which then again connects to another. This way you would need to have only one connection in your application.

To query the data 'behind' the linked server you need to use special four-part notation for tables. If this feels cumbersome you can always define a view to hide the location of a table.

More about linked servers: Linked Servers[^]
Shanu2rick 12-Jan-13 4:17am
@Mika: Didn't knew about the Linked Servers. Thanks for sharing.
Mika Wendelius 12-Jan-13 4:19am
You're welcome :)
CHill60 26-Mar-13 6:09am
Followed a link from another solution today ( and found this solution my +5
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Add Two ConnectionString in your Web.config file with different name's like this:

    <add name="ConnectionString1" connectionstring="Initial Catalog=dbName1;Data Source=ServerName;Integrated Security=SSPI;" providername="System.Data.SqlClient" />
    <add name="ConnectionString2" connectionstring="Data Source=dbName2;Initial Catalog=ServerName;Integrated Security=True">
      providerName="System.Data.SqlClient" />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 12 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100