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.

Mate
  • 241
  • 1
  • 2
  • 11
  • 1
    okay, USE GO will work, but is there any UI command? – Mate Aug 11 '16 at 12:13
  • 1
    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. – JakeJ May 30 '18 at 14:24

5 Answers5

19

Just click "Execute" and it will reconnect again.

energyguy78
  • 301
  • 3
  • 4
  • 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. – Nick Straguzzi Feb 25 '22 at 19:31
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

Tikke
  • 131
  • 2
  • 8
2

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

Peter
  • 21
  • 2
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.

0

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

Serge Nazarenko
  • 139
  • 1
  • 6