Best Software for 2025 is now live!

How can I work on the same query if the connection is lost (timeout) and then I reconnect?

When I let the SQL session expire, I try to reconnect again and use the same query file I was working on, but it doesn't let me continue because it's says that I'm not connected to any database. So I have to restart the application, connect again and then the query will work.
4 comments
Looks like you’re not logged in.
Users need to be logged in to answer questions
Log In
Michel S.
MS
Database Developer
0
Depends what you are doing. If you ran a stored procedure than it will finish but that also depends how you coded transaction handling in the stored procedure. If you are just doing a simple select of an insert and the connection is broken. Then Sqlserver will rollback in case of an insert. A simple select will be terminated. If you want to guarantee the fact that you want to be able to work on after a connection loss then you should transfer your SQL into a stored procedure and in that stored procedure you program that the next time the stored procedure is executed ( after a connection loss) that it will continue the job it was doing by looking into a status table where it can pick up were it left.
Looks like you’re not logged in.
Users need to be logged in to write comments
Log In
Reply
AG
Software Developer
0
To adjust the query timeout, access the server properties through the right-click menu, navigate to Remote server connections, and locate the remote query timeout field. Enter a large number in that field.
Looks like you’re not logged in.
Users need to be logged in to write comments
Log In
Reply
JE
Computer Systems Specialist
0
When this happens to me in SQL Server Management Studio, I just have to type USE {your database name here} and then select only that statement and execute it. This re-establishes my connection and I can continue to work on my query.
Looks like you’re not logged in.
Users need to be logged in to write comments
Log In
Reply
Sergio Antonio E.
SE
POS Expert en SoftTek
0
You can change the timeout for the query: In the object explorer, right click a server and select properties. Go to Remote server connections, look for the remote query timeout field; then type or choose a value from 0 to 2,147,483,647 to establish the maximum number secs that SQL Server will wait before timing out
Looks like you’re not logged in.
Users need to be logged in to write comments
Log In
Reply