Ensure connection open for OE queries and fix connection disposal (#359)

* Ensure connection open for OE queries and fix connection disposal
- Dispose connection in Metadata service, to ensure we cleanly dispose and don't rely on garbage colleciton
- Fixed issue where if the connection was closed, expanding databases in the Server would fail. This is because SMO doesn't always reopen the connection, certainly not for Server level queries. The solution is to always check if open and reopen.
- Added unit tests for this, which required mocking the relevant IsOpen / OpenConnection methods. Refactored SMO wrapper calls into a dedicated class file to handle this
This commit is contained in:
Kevin Cunnane
2017-05-25 18:26:52 -07:00
committed by GitHub
parent c545b74372
commit bbd0972dde
6 changed files with 218 additions and 35 deletions

View File

@@ -92,7 +92,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
Enumerator en = new Enumerator();
Request request = new Request(new Urn(urn));
ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
if (!serverConnection.IsOpen)
{
serverConnection.Connect();
}
EnumResult result = en.Process(serverConnection, request);
urns = GetUrns(result);