Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

i make a website and now further process i want to apply select query from the another database which i have not connect or not use connection string.

so, i just want to how to Apply select query in another page of my website from the second database.

if it is possible , so please tell me how ?

Thanks and Regards...
Mitesh
Posted
Comments
db7uk 19-Jun-12 4:49am    
Is the second database on the same server as the first? You can just add another connection string to the app / web.config and use that?????
[no name] 19-Jun-12 4:53am    
yes, another database is on same server.so, how can i add in webconfig

In web.config, you can add multiple connection strings as follows:
XML
<connectionStrings>
<add name="connStr1" connectionString="server=localhost;database=yourDb;uid=yourUser;password=password;" />
<add name="connStr2" connectionString="server=localhost;database=yourDb;uid=yourUser;password=password;" />
</connectionStrings>

For reading, use the following code:
C#
string connStr1 = ConfigurationManager.ConnectionStrings["connStr1"].ConnectionString;
string connStr2 = ConfigurationManager.ConnectionStrings["connStr2"].ConnectionString;
 
Share this answer
 
Just try the following query. Assume your first database is named as Database1 and second one is named as Database2

SQL
Select a.*,b.* from Database1.Table1 as a, Database2.Table1 as b


Hope this helps

Regards
Sebastian
 
Share this answer
 
Hi ,
You can also use WEB SERVICE
Check this Article
Your first C# Web Service[^]
Best Regards
M.Mitwalli
 
Share this answer
 
Hi,

You can use ChangeDatabase() method of the SqlConnection class.

Once the Database is changed you can fire the command.

Another approach is use the <connectionstrings> section of the Web.Config file. Use the ConfigurationManager class to retreive the second connection strong.

Regards,
Raghu
 
Share this answer
 
Yes it is possible to change database in an application.

please see the following example

SQL
select * from databasename.dbo.tablename


remember, it is for same server.
 
Share this answer
 

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