mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 17:23:27 -05:00
Fixing the bug with connections on database make restore fail (#473)
* closing the connections that don't need to be open and keeping track of the connections that should stay open
This commit is contained in:
@@ -27,13 +27,12 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
{
|
||||
private ConnectionSummary connectionSummary;
|
||||
private ServerInfo serverInfo;
|
||||
private string connectionUri;
|
||||
private Lazy<SmoQueryContext> context;
|
||||
private ConnectionService connectionService;
|
||||
private SmoWrapper smoWrapper;
|
||||
private SqlServerType sqlServerType;
|
||||
private ServerConnection serverConnection;
|
||||
|
||||
public ServerNode(ConnectionCompleteParams connInfo, IMultiServiceProvider serviceProvider)
|
||||
public ServerNode(ConnectionCompleteParams connInfo, IMultiServiceProvider serviceProvider, ServerConnection serverConnection)
|
||||
: base()
|
||||
{
|
||||
Validate.IsNotNull(nameof(connInfo), connInfo);
|
||||
@@ -42,12 +41,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
|
||||
this.connectionSummary = connInfo.ConnectionSummary;
|
||||
this.serverInfo = connInfo.ServerInfo;
|
||||
this.connectionUri = connInfo.OwnerUri;
|
||||
this.sqlServerType = ServerVersionHelper.CalculateServerType(this.serverInfo);
|
||||
|
||||
this.connectionService = serviceProvider.GetService<ConnectionService>();
|
||||
|
||||
this.context = new Lazy<SmoQueryContext>(() => CreateContext(serviceProvider));
|
||||
this.serverConnection = serverConnection;
|
||||
|
||||
NodeValue = connectionSummary.ServerName;
|
||||
IsAlwaysLeaf = false;
|
||||
@@ -130,43 +127,22 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
private SmoQueryContext CreateContext(IMultiServiceProvider serviceProvider)
|
||||
{
|
||||
string exceptionMessage;
|
||||
ConnectionInfo connectionInfo;
|
||||
SqlConnection connection = null;
|
||||
// Get server object from connection
|
||||
if (!connectionService.TryFindConnection(this.connectionUri, out connectionInfo) ||
|
||||
connectionInfo.AllConnections == null || connectionInfo.AllConnections.Count == 0)
|
||||
{
|
||||
ErrorStateMessage = string.Format(CultureInfo.CurrentCulture,
|
||||
SR.ServerNodeConnectionError, connectionSummary.ServerName);
|
||||
return null;
|
||||
}
|
||||
//TODO: figure out how to use existing connections
|
||||
DbConnection dbConnection = connectionInfo.AllConnections.First();
|
||||
ReliableSqlConnection reliableSqlConnection = dbConnection as ReliableSqlConnection;
|
||||
SqlConnection sqlConnection = dbConnection as SqlConnection;
|
||||
if (reliableSqlConnection != null)
|
||||
{
|
||||
connection = reliableSqlConnection.GetUnderlyingConnection();
|
||||
}
|
||||
else if (sqlConnection != null)
|
||||
{
|
||||
connection = sqlConnection;
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorStateMessage = string.Format(CultureInfo.CurrentCulture,
|
||||
SR.ServerNodeConnectionError, connectionSummary.ServerName);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Server server = SmoWrapper.CreateServer(connection);
|
||||
return new SmoQueryContext(server, serviceProvider, SmoWrapper)
|
||||
Server server = SmoWrapper.CreateServer(this.serverConnection);
|
||||
if (server != null)
|
||||
{
|
||||
Parent = server,
|
||||
SqlServerType = this.sqlServerType
|
||||
};
|
||||
return new SmoQueryContext(server, serviceProvider, SmoWrapper)
|
||||
{
|
||||
Parent = server,
|
||||
SqlServerType = this.sqlServerType
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (ConnectionFailureException cfe)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user