Update I get an Invalid object name error for the DataBaseA.dbo.templates
I wish to Inner join two tables from seperate databases on the same server (Local).
But i can't seem to get it work. Also i don't understand how i should be handling my connectionstring, as i'm currently setting the current connection to the connectionstring of my database. But in this example i'm trying to connect to two different databases in the same query.
This is my SQL code so far:
"SELECT a.template.*, b.c_template.* FROM DatabaseA.dbo.templates a INNER JOIN DatabaseB.dbo.c_template b ON a.id = b.template_id"
And this is my connectionstrings:
<add name="Unit" connectionString="Data Source=(LocalDB)v11.0;AttachDbFilename=|DataDirectory|DatabaseA.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="Content" connectionString="Data Source=(LocalDB)v11.0;AttachDbFilename=|DataDirectory|DatabaseB.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
See Question&Answers more detail:os