mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user