SQL Server Management Studio: Reconnect query tab after database restore/lost connection
Asked Answered
W

5

15

I have several long queries in SQL Server Management Studio. If my connection is lost/broken (e. g. after Restore of the database), how can I reconnect my SQL query tab to the database? My context menu for the connection only contains deactivated items...

It is not too much work to copy everything, open a new SQL query tab on my database and paste it, but "smart" is something completely different.

Willyt answered 11/8, 2016 at 12:10 Comment(2)
okay, USE <database> GO will work, but is there any UI command?Willyt
I've seen that energyguy78's method has been working for me in the past. Any valid SQL command, highlight that if you don't want to run the full page's query, then click "execute". It will reconnect if it had been connected before.Atc
G
19

Just click "Execute" and it will reconnect again.

Gadgetry answered 28/10, 2017 at 21:53 Comment(1)
Correct. Just bear in mind, though, that this will create a new session, so anything you had that relied on the previous one (the session ID, any temp tables, etc.) will be lost and need to be re-created.Attribution
P
10

After reconnecting the database - as described here - you must still select your database from "available databases" pull down menu. Then your queries start to work

Phalan answered 13/2, 2018 at 19:15 Comment(0)
S
3

Click the 'Change Connection' icon and it will allow you to reconnect back to the DB

Syncope answered 22/2, 2017 at 9:39 Comment(1)
What if the 'Change Connection' icon is grayed out?Saxecoburggotha
B
1

I see this happening only when I use F5 for the execution of the script and I get error. Only then the connection options are disabled for some reason.

Anyway the solution to this state is clicking the Execute button (or context menu button if you right click) as energyguy78 suggested. That should re-connect the tab.

Budge answered 3/1, 2018 at 15:55 Comment(0)
E
0

Click button Connect or Change Connection, if Connect button doesn't work.

Eustasius answered 21/11, 2017 at 12:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.