Hello
I am working in SQLSERVER 2008 and i want to fetch data from different server table please define how to fetch data from different server and also different database?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Davin MartynPosted Mar 23, 2015, 1:01 AM
Pankaj Kumar ChoudharyPosted Mar 20, 2015, 9:47 PM
SqlConnection con1 = new SqlConnection("Data Source=@Server_Name;initial catalog=@Database_Name; integrated security=true");
SqlConnection con2 = new SqlConnection("Data Source=@Server_Name;initial catalog=@Database_Name ; integrated security=true");
Khargesh RajputPosted Mar 20, 2015, 10:24 AM
Now.in.web.config add two conectionstring
Named cnstr1 for.server1 and cnstr2. For server2.
Now on. Connection class or your page as you want; based on condition if you want database from server1 to use then. Add cnstr1 and execute query and if want to.usse server2 then add cnstr2 and write query to use server2
In detail
in web.config
and in connection class
var conn1 = ConfigurationManager.ConnectionStrings["cnstr1"].ConnectionString;
var conn2 = ConfigurationManager.ConnectionStrings["cnstr2"].ConnectionString;
now use these connectionstrings in your sqlconnection
Davin MartynPosted Mar 20, 2015, 9:29 AM
Khargesh RajputPosted Mar 17, 2015, 6:37 AM