Query Editor windows – context? What context.

Here is a post I made over on the MSDN Sql Management Tools Forum (http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=84&SiteID=1) about opening a query editor window and how it gets server/database context or not and when it asks you for connection or it doesn't.

If you ask for a new query window via File->New->Database Query (or any other), or the toolbar button to the RIGHT of the "New Query" button, we ALWAYS prompt for a connection, you can press cancel and you will get a query window that is disconnected. We will not prompt for a connection until you attempt to execute that query or ask to connect explicitly via the Query->Connection->Connect option, or toolbar button under the New Query button.

If you ask for a new query window via File->New->Query With Current Connection, or the New Query button, or Ctrl+N, then we create a new query window with whatever current connection context you have. If the focus is in a Query Window we will create a new one with the same connection (this is the same behavior as QA). If you have focus in Object Explorer or Registered servers on a server, we will create a query window connected to that server.

Finally if you ask for a new query window with the current connection (as above) but there is NO current context: no query window, focus on a disconnected query window, focus on the server type node in the registered servers window then we will prompt you for a connect and in this case, if you press cancel, the new query window generation is stopped.

If we end up connecting you to a server you didn't want or not connecting you at all you can click on the disconnect toolbar or the re-connect toolbar (or their associated menu's under Query->Connections) and get the query window to the right server.

Finally there are some context menu's to be aware of. From a registered server you can right click and go into the "Connect" menu and select Query Window. This will open a query window connected to this server (regardless if it is connected in Object Explorer).

From a connected server in OE you can right click and use the New Query menu option to open a query connected to that server. If you select a database in the Object Explorer and do a New Query from there, then you will be connected to that server with the selected database as the current database.

These same concepts apply to an Analysis Server connection just as they do to a Relational Server connection.

Play around with it and hopefully it will allow you to achieve what you would like, when you would like it

Skip to main content