Last post Jan 15, 2009 01:13 PM by OwainGDWilliams
Jan 15, 2009 11:11 AM|OwainGDWilliams|LINK
Feels like I'm hitting my head against a brick wall with this problem.
I have setup two connection strings to two databases and setup the relevant information in the web.config file to point to the databases.
string cs2 = ConfigurationManager.ConnectionStrings["ContractConnectionString"].ConnectionString;
string cs = ConfigurationManager.ConnectionStrings["IPRConnectionString"].ConnectionString;
conn = new SqlConnection(cs);
conn2 = new SqlConnection(cs2);
I then have my SqlCommand
Now, as I write this I have just noticed at the end of the SQL command it calls on conn, but how would I get it to call on conn2 as well?
If this isnt the correct way to query 2 databases at the same time can you please tell me how.
What I am trying to do is search 2 databases which are both on the same server. One database holds information for full time employess and the second holds information for contracters, so when someone does a search the app will search both
databases and display the employees who match the search criteria from both databases.
If you need any more info just shout.
Jan 15, 2009 12:59 PM|che3358|LINK
I don't think you need two connection strings here. If the two DBs are on same server, you just use DBName.dbo.TableName. If they are on different servers, you can create a Linked Server, then use ServerName.DBName.dbo.TableName.
In your case, you can try:
SELECT * FROM SCSStaff WHERE surname like @surname AND forenames like @forename UNION SELECT * FROM
YourSecondDBName.dbo.nonScsStaff WHERE surname like @surname AND forenames like @forename ORDER BY surname
Jan 15, 2009 01:13 PM|OwainGDWilliams|LINK
Such a simple change and it works perfectly!! Thank you for your help.
Will mark your post as answer.