Using Multiple servers and dbs in a query
On Sept 2016 Joe wrote:
This strategy will work if all the databases in question have the same schema.
You can retrieve the connection string from another query as follows:
Util.GetMyQueries().First (x => x.FilePath == "...").GetConnectionInfo().DatabaseInfo.GetCxString()
If I get the connection string from another query how do I use it in a new query for a specific block of code? Can I use
this.Connection.ConnectionString to flip my query to another connection and then back again?
Comments
If you are using LINQ to SQL, you can switch to the secondary database using this code:
Note that the following will also work if you are on the same server (but lacks object tracking):