Reopen connections prior to creating query execution data readers (#704)

* Reopen connections prior to creating query execution data readers

* Reopen connection if an exception was rasied executing the query

* Fix unit tests
This commit is contained in:
Karl Burtram
2018-10-08 12:41:04 -07:00
committed by GitHub
parent acf7634425
commit 7c1710d396
4 changed files with 39 additions and 0 deletions

View File

@@ -1528,5 +1528,28 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
return null;
}
public static void EnsureConnectionIsOpen(DbConnection conn, bool forceReopen = false)
{
// verify that the connection is open
if (conn.State != ConnectionState.Open || forceReopen)
{
try
{
// close it in case it's in some non-Closed state
conn.Close();
}
catch
{
// ignore any exceptions thrown from .Close
// if the connection is really broken the .Open call will throw
}
finally
{
// try to reopen the connection
conn.Open();
}
}
}
}
}