Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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

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

share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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