My situation:

Using Microsoft SQL Server Management Studio 2005, I connect to a server -- I’ll call it Prod -- using Windows Authentication.

Within this Prod server there are multiple databases: dbA, dbB and dbC.

On a previous computer, if I had the ‘Tables’ folder for a particular database (e.g. dbB) selected and opened an existing query (.sql file) from a local or network directory, the existing query would open “connected” to the selected database (dbB). On my replacement computer, existing queries always open connected to 'master' on the SQL Editor toolbar instead of the expected dbB database.

A minor inconvenience, yes, but if there is a simple setting I can modify or update to restore this preferred behavior (queries open into previously selected database), I'd appreciate learning how to do it.

Thanks in advance for any suggestions.

3 Answers 3


Right-click, "Change Connection", "Options", and you can enter or browse a database.

Yep, it's a pain until you "train" SSMS...

  • Just a note - right-click in the query window, or click Options on the Connect to Server dialog ( when yo are connecting )
    – Bakudan
    Jul 4, 2017 at 12:15

Some options that you have:

  • pointed already by gbn (change current connection)
  • click first in the databases tree and then click 'new query' or 'open file' - they will be open in the scope of the previously selected database
  • choose a preferred (default) database for the user (either in Security - user properties or in connection preferences)
  • always use USE in your queries and not rely on Management Studio :-)
  • add to the previous option the sqlcmd mode of Management Studio (tools - options - query execution - use sqlcmd mode) and this allows you to make use in your scripts of the :connect command which will allow you to run a specific script only in the context of a specific server

For SQL Server 2014, right click on any white area of query, select connection, change connection, options, connection properties, connect to database, find your database in drop-down and then click on connect!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.