Sql-server – Reconnect “not connected” query windows in SSMS to original connection

connectivitysql serverssms

Is there a simple way to reconnect a query window that is "not connected" to the original connection that was used by that query without manually picking the server name needed? If I click the Connect button on the SQL Editor toolbar or right click -> Connection -> Connect… it defaults the server name to the last connection I used in that SSMS session, not to the last connection used by that specific query window.

After taking my laptop home at the end of the day, all the open windows will be set to not connected the next time I use it. Ideally, I'd like to be able to reconnect all to their original connections, but I don't know that even the one query at a time is possible.

Best Answer

In SSMS, if you run a query in a disconnected window, it will attempt to re-connect to the prior connection. You will get an error, then the window will reconnect. If you run a query like SELECT 1;, it will reconnect without having to do any data access/manipulation.

However, I'm a bit timid about relying on this to remember what server I was previously connected to. While I have noticed this to be the behavior, it is not documented, so I do not fully trust that it is "as designed" vs "the way it works." You should always make sure you are connected to the correct server before running any scripts.