I have three databases on three different servers that I need to join and show the result in a asp:gridview. I have the query working now as the result of asp:SqlDataSource using the connection string to one database, but my problem is that I specify the server, database and table for the other two databases.
- How do modify my query to use a connection string to all of the
databases (C#, asp example)? - Do I do my query in the aspx file or should I do the query in the cs file?
- How do I attach my result to the gridview if I do the join in the cs file? The data could be different once I leave this page and come back.
My current <asp:SqlDataSource> code is this –
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT A.batchname AS IndexBatchNumber, a.clientkey, a.packagetrackingid, a.statusflag, f.Name AS Client, SELECT GroupValue FROM FSDev.dbo.ClientGroup WHERE ClientKey = a.clientkey AND GroupCode = 'TIME ZONE') AS Timezone, (SELECT fc.special_instr FROM SQL2.sysdba.FC_SLX_TEST.FC_PKG_TRKG fc WHERE
fc.fc_Pkg_trkgid = a.PackageTrackingID) AS RushFunding FROM BatchExport a, InvoiceExport b, FSDev.dbo.Clients f WHERE a.batchname = b.batchname AND a.clientkey = f.ClientKey AND a.statusflag = 1 "></asp:SqlDataSource>
I have been able to solve this by doing two things. Since the databases are all MSsql, I used the link capabilities to join them together. That way I only have to have a single connection string. In order not to have to change the SQL code when moving to production servers, I had the DBA create stored procedures for all of my queries. This way I only have to change the connection strings.