Click here to Skip to main content
15,911,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a project which needed to fetch two different database records into one page.

How can i do this
Posted
Comments
Mehdi Gholam 14-Nov-11 7:15am    
From different tables or the same table?
Prince Antony G 14-Nov-11 23:52pm    
add connection string for two database and use it..

SQL
SELECT
        *
FROM
        [SERVER2NAME].[THEDB].[THEOWNER].[THETABLE]
 
Share this answer
 
Comments
Amod Kumar Jaiswal 14-Nov-11 7:18am    
how to set connection string of second database.
if just for join you can use JOIN with SELECT query
Selecting data from different databases[^]

If databases are in different locations or types then
use OPENROWSET[^]
or
OPENDATASOURCE[^]
or
Linked Servers[^]
 
Share this answer
 
Comments
Amod Kumar Jaiswal 14-Nov-11 7:28am    
how to set connection string of second database.
'Link Server' is your answer...

you can link one server (sql|Oracle or any oledb) to your primary SQL server 2005 databse.. after you have linked it you can query your primary and secondary database as you are wotking on a single server. its very simple too!! :)

find how to setup link server in SQL server at MSDN :)

http://msdn.microsoft.com/en-us/library/ms188279.aspx[^]

mark as answer if satisfied.. it motivates :)
 
Share this answer
 
Hello,

Please go through below links


Tool to script Linked Servers in SQL Server 2000[^]


Download the code and use the part of code required for you.
 
Share this answer
 
Comments
Amod Kumar Jaiswal 16-Nov-11 2:09am    
i have connection string into web config file and i am reading database from config file.

i want to bind grid which is reading data from two database, how can i do this?
XML
<add name="Constring" ........ />
 <add name="Constringnew" ........../>


C#
String conn = System.Configuration.ConfigurationManager.ConnectionStrings["Constring"].ToString();

String conn1 = System.Configuration.ConfigurationManager.ConnectionStrings["Constringnew"].ToString();


Try this
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900