I have four databases names Server1, Server2, Server3, and Server4 which contains a single table each.
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["Server1"].ToString());
SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["Server2"].ToString());
SqlConnection con3 = new SqlConnection(ConfigurationManager.ConnectionStrings["Server3"].ToString());
SqlConnection con4 = new SqlConnection(ConfigurationManager.ConnectionStrings["Server4"].ToString());
i want to fire the following command in C# :-
select id, filename, Server from Server1.dbo.UploadedData where userid='1'
union
select id, filename,Server from Server3.dbo.UploadedData where userid='1'
union
select id, filename,Server from Server3.dbo.UploadedData where userid='1'
union
select id, filename,Server from Server4.dbo.UploadedData where userid='1'
for executing this command i have to pass connection object of each database.
like...
cmd= new SqlCommand("select id, filename, Server from Server1.dbo.UploadedData where userid='1'union select id, filename,Server from Server3.dbo.UploadedData where userid='1' union select id, filename,Server from Server3.dbo.UploadedData where userid='1' union select id, filename,Server from Server4.dbo.UploadedData where userid='1',con1,con2,con3,con4 ");
this is not possible to pass 4 connection object.......what will be the other best option??