I have to join queries from multiple databases, something like:
SELECT T1.*, T2.* FROM DatabaseA.dbo.Table1 AS T1
INNER JOIN DatabaseB.dbo.Table2 AS T2 ON T1.ID = T2.ID
My questions:
- How should I setup the connection string of
System.Data.SqlClient.SqlConnection? Should I omit or leave empty theInitial Catalog? Should I set it toDatabaseA? - Is this a good way to perform this task? I'm thinking to prepare a third DB without tables but with a view with that
SELECT(I can't put a view in the existing databases). Query usually is executed in 10/15 seconds but user has to wait so even few seconds less will be appreciated.
All DBs share the same login credentials.