Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Connection lost to Azure SQL DB #2933
Issue Type: Bug
I connected to Azure SQL DB, ran a few queries, left the query window open for about 15-20 minutes and then went to run another query and got this error message:
Azure Data Studio version: Azure Data Studio 1.1.2-insider (58f950f, 2018-10-15T03:08:44.410Z)
The query editor will try to hold an open connection for the duration of the document's lifetime. i.e., if you run a SQL script multiple times it will reuse the connection. This is generally what you want to avoid having to wait to reconnect each time you run a query.
The downside is that if the connection is closed the UX can be what you're seeing. You run a query and get a general connectivity exception. We recently made a change that when there is any exception raised during query execution we'll close and reopen the connection. This means that subsequent reexecutions will have a new "good" connection and likely succeed.
The query execution code checks whether the SqlConnection is Open prior to running the query, but unfortunately the SqlConnection will often incorrectly report as Open until it's used and throws, at which point it then correctly reports as closed.
A couple ideas to "smooth out" the inactive editor scenario are (1) we could automatically reopen connections that haven't been used for several minutes, this would cause a little delay when the editor becomes active again, but would avoid hitting these errors in many cases (2) we could have a connection "watchdog" component that sent simple "no-op" queries periodically on all tracked connections to ensure they are actually still open, this would allow us to close\reopen connections transparently to users.
For reference, I don't think SSMS does either of these mitigation, and relies on Connections to be generally reliable. I'll double-check to verify this. Also, please note we are seeing Socket connections to SQL Server generally less reliable on macOS .Net Core clients than on Windows clients.