Actually it does not really matter on which database you connect initially.
When referencing tables (or any other database objects) you can youse a 3-part-name where the first part defines the database of the object.
select * from Database1.dbo.Table1
select * from Database2.dbo.Table1