# 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.

##### Post Metadata
- Posted at: almost 7 years ago
- Author title: Solutions Analyst
- Net upvotes: 2


## Comments
### Comment 1

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.

##### Comment Metadata
- Posted at: over 6 years ago
- Author title: Database Developer



### Comment 2

change the timeout of the query; right click a-&gt; server =&gt; select properties -&gt; Remote server connections =&gt; remote query timeout field. Give a big number there

##### Comment Metadata
- Posted at: over 6 years ago
- Author title: Software Developer 



### Comment 3

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.

##### Comment Metadata
- Posted at: almost 7 years ago
- Author title: Computer Systems Specialist



### Comment 4

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

##### Comment Metadata
- Posted at: almost 7 years ago
- Author title: POS Expert en SoftTek




## Related Product
[Microsoft SQL Server](https://www.g2.com/products/microsoft-sql-server/reviews)

## Related Category
[Relational Databases](https://www.g2.com/categories/relational-databases)

## Related discussions
- [How well does Trello scale into a larger team?](https://www.g2.com/discussions/1-how-well-does-trello-scale-into-a-larger-team)
  - Posted at: about 13 years ago
  - Comments: 6
- [Can we please add a new section](https://www.g2.com/discussions/2-can-we-please-add-a-new-section)
  - Posted at: about 13 years ago
  - Comments: 0
- [Quantifiable benefits from implementing your CRM](https://www.g2.com/discussions/quantifiable-benefits-from-implementing-your-crm)
  - Posted at: about 13 years ago
  - Comments: 4


