SSMS – Prevent Open Tab from Querying DB After Disconnect
ssms
In SSMS if you have a tab open with a query and then you disconnect the database you can still run the query after disconnecting.
is there a way to prevent SSMS from running a query after server is disconnected?
Best Answer
The Object Explorer pane and the Query pane are independent. You can have the Object Explorer connected without having a Query connected, and vice versa.
The menu option you probably want is Query -> Connection -> Disconnect.
In 2005 at least, hit F5 to re-run your query. SSMS will determine it is no longer connected and then prompt you to reconnect. If I recall correctly, 2005 will put you back into the same database while 2008 puts you into your default catalog. A second execution of F5 will actually run the command. I've never had a semaphore timeout but it works for other disconnect scenarios.
To fix this issue: Tools \ Options \ Keyboard. Bring up the command in the "Show commands containing:" list. Then in the "Press shortcut keys:" text box press CTRL+Tab and click Assign. This will re-assign the command back to itself, but fixed the "sticky" window. Just had the same issue. Hope this helps.
Best Answer
The Object Explorer pane and the Query pane are independent. You can have the Object Explorer connected without having a Query connected, and vice versa.
The menu option you probably want is Query -> Connection -> Disconnect.
HTH