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

@@ -30,7 +30,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
private string connectionUri;
private Lazy<SmoQueryContext> context;
private ConnectionService connectionService;
private SmoServerCreator serverCreator;
private SmoWrapper smoWrapper;
private SqlServerType sqlServerType;
public ServerNode(ConnectionCompleteParams connInfo, IMultiServiceProvider serviceProvider)
@@ -56,19 +56,19 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
Label = GetConnectionLabel();
}
internal SmoServerCreator ServerCreator
internal SmoWrapper SmoWrapper
{
get
{
if (serverCreator == null)
if (smoWrapper == null)
{
ServerCreator = new SmoServerCreator();
smoWrapper = new SmoWrapper();
}
return serverCreator;
return smoWrapper;
}
set
{
this.serverCreator = value;
this.smoWrapper = value;
}
}
@@ -161,8 +161,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
try
{
Server server = ServerCreator.Create(connection);
return new SmoQueryContext(server, serviceProvider)
Server server = SmoWrapper.CreateServer(connection);
return new SmoQueryContext(server, serviceProvider, SmoWrapper)
{
Parent = server,
SqlServerType = this.sqlServerType
@@ -187,16 +187,4 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return context.Value;
}
}
/// <summary>
/// Internal for testing purposes only
/// </summary>
internal class SmoServerCreator
{
public virtual Server Create(SqlConnection connection)
{
ServerConnection serverConn = new ServerConnection(connection);
return new Server(serverConn);
}
}
}