1

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

  • Might be be design. See dba.stackexchange.com/questions/183432/… – gbn Feb 18 at 7:07
  • The query window and the object explorer are separate. Sure, you can open a query window from object explorer and it will use the same connection. But you can tell that it is separate by when SSMS crashes. After a crash, SSMS will attempt to repopen the object explorer and all the query tabs, asking for a new connection everytime. – Anthony Genovese Feb 18 at 14:24
2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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