Fix/restore connection issue (#416)

* fixed the connection issue used for restore

* fixed a test
This commit is contained in:
Leila Lali
2017-07-17 15:57:30 -07:00
committed by GitHub
parent 836847ce15
commit d5b2bcdcb7
3 changed files with 34 additions and 6 deletions

View File

@@ -5,12 +5,16 @@
using System;
using System.Linq;
using System.Data.Common;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
{
@@ -219,7 +223,24 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
if (connInfo != null)
{
Server server = new Server(new ServerConnection(connInfo.ConnectionDetails.ServerName));
SqlConnection connection;
DbConnection dbConnection = connInfo.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
{
Logger.Write(LogLevel.Warning, "Cannot find any sql connection for restore operation");
return null;
}
Server server = new Server(new ServerConnection(connection));
RestoreDatabaseTaskDataObject restoreDataObject = new RestoreDatabaseTaskDataObject(server, restoreParams.DatabaseName);
restoreDataObject.RestoreParams = restoreParams;