Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using the users input I've generated a string via string.format to access the sql server then used SqlAdapter to run my SQL Query and finally pass that to a DataTable to be displayed later.

The problem now is that I want to access multiple servers to get the same data from each of them (column names are the same on all servers).

What I have tried:

C#
for(int i =0;i< dataList.Count;i++)
{
connectionString = string.Format(theString, data); //address for the server "data:-is the server id"

// [this area here is where I use my sql query]

}
Posted
Updated 9-Oct-18 4:35am
v3
Comments
MadMyche 9-Oct-18 10:12am    
What are the results of your attempt? Any errors? Are the SQL servers "linked"?
Graeme Cooper 9-Oct-18 10:18am    
my major restriction is that I can't link servers. Apart from that my connectionstring is being overloaded.
F-ES Sitecore 9-Oct-18 10:19am    
Yes it's possible. You could keep a List of the server names and loop through the names in the list passing them to your string.Format function to get a connection string for that server, then execute your SQL.
Graeme Cooper 9-Oct-18 10:30am    
thanks for the reply, I got it working (guess I was being a little impatient)

1 solution

There are a number of ways you can handle this issue.

0) you can create an ado class that is initialized with a different connection string (inheriting from a base class that provides query functionality)

1) You can create a static class that has a method that allows you to specify the server as a parameter for every query

2) and so on...

3) and so forth...
 
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