2

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?

disconnect

Nerdroid
  • 123
  • 1
  • 6

2 Answers2

3

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

la_mochila
  • 116
  • 1
0

I don't think that you can prevent it from querying. What in my humble opinion is most annoying about that, is if you click execute, Management Studio reconnects and queries the default database for the logged in user with the statement that is still open in your query window.

To prevent that, just make it to your habit to always write a

use your_database_name

statement in the first row of your query windows, so the annoying

could not execute query

won't appear anymore

D M
  • 445
  • 5
  • 10