diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs index cca2e871..81744de5 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs @@ -11,8 +11,6 @@ using System.Resources; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Sdk.Sfc; -using Microsoft.SqlServer.Management.Diagnostics; -using System.Globalization; using Microsoft.Data.SqlClient; using System.Collections.Generic; using System.Diagnostics; @@ -362,7 +360,7 @@ WHERE do.database_id = @DbID } else { - throw ex; + throw; } } @@ -574,7 +572,7 @@ WHERE do.database_id = @DbID } else { - throw ex; + throw; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs index 6f14ec98..44c4ea38 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs @@ -9,11 +9,8 @@ using Microsoft.SqlTools.ServiceLayer.Admin.Contracts; using Microsoft.SqlTools.ServiceLayer.Management; using Microsoft.SqlTools.Utility; using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; using System.Xml; namespace Microsoft.SqlTools.ServiceLayer.Admin @@ -168,8 +165,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin private static string GetBackupDate(DateTime backupDate) { - if (backupDate == null - || backupDate < minBackupDate) + if (backupDate < minBackupDate) { return SR.NeverBackedUp; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs index d8aa50fa..3dd7e697 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs @@ -6,10 +6,6 @@ using System; using System.Data; using System.Collections.Generic; -using System.Text; -using Microsoft.SqlServer.Management.Common; -using Microsoft.SqlServer.Management.Sdk.Sfc; -using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Smo.Agent; using Microsoft.SqlTools.ServiceLayer.Agent.Contracts; @@ -52,9 +48,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent Category = job.Category, CategoryId = job.CategoryID, CategoryType = job.CategoryType, - LastRun = job.LastRun != null ? job.LastRun.ToString() : string.Empty, - NextRun = job.NextRun != null ? job.NextRun.ToString() : string.Empty, - JobId = job.JobID != null ? job.JobID.ToString() : null, + LastRun = job.LastRun.ToString(), + NextRun = job.NextRun.ToString(), + JobId = job.JobID.ToString(), OperatorToEmail = job.OperatorToEmail, OperatorToPage = job.OperatorToPage, StartStepId = job.StartStepID, @@ -82,9 +78,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent Category = job.Category, CategoryId = job.CategoryID, CategoryType = job.CategoryType, - LastRun = job.LastRun != null ? job.LastRun.ToString() : string.Empty, - NextRun = job.NextRun != null ? job.NextRun.ToString() : string.Empty, - JobId = job.JobID != null ? job.JobID.ToString() : null, + LastRun = job.LastRun.ToString(), + NextRun = job.NextRun.ToString(), + JobId = job.JobID.ToString(), OperatorToEmail = job.OperatorToEmail, OperatorToPage = job.OperatorToPage, StartStepId = job.StartStepID, diff --git a/src/Microsoft.SqlTools.ServiceLayer/AzureFunctions/AddSqlBindingOperation.cs b/src/Microsoft.SqlTools.ServiceLayer/AzureFunctions/AddSqlBindingOperation.cs index 8296c156..b046bdad 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/AzureFunctions/AddSqlBindingOperation.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/AzureFunctions/AddSqlBindingOperation.cs @@ -91,7 +91,7 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureFunctions catch (Exception ex) { Logger.Write(TraceEventType.Information, $"Failed to add sql binding. Error: {ex.Message}"); - throw ex; + throw; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/AzureFunctions/GetAzureFunctionsOperation.cs b/src/Microsoft.SqlTools.ServiceLayer/AzureFunctions/GetAzureFunctionsOperation.cs index 2ff38a98..d8739f54 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/AzureFunctions/GetAzureFunctionsOperation.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/AzureFunctions/GetAzureFunctionsOperation.cs @@ -69,7 +69,7 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureFunctions catch (Exception ex) { Logger.Write(TraceEventType.Information, $"Failed to get Azure functions. Error: {ex.Message}"); - throw ex; + throw; } } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupOperation/BackupOperation.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupOperation/BackupOperation.cs index 46359b6f..478ae741 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupOperation/BackupOperation.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupOperation/BackupOperation.cs @@ -11,7 +11,6 @@ using Microsoft.Data.SqlClient; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Smo; -using Microsoft.SqlTools.ServiceLayer.Admin; using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts; using Microsoft.SqlTools.ServiceLayer.Management; using Microsoft.SqlTools.ServiceLayer.TaskServices; @@ -453,10 +452,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery result = constDeviceTypeMediaSet; } } - catch (Exception ex) - { - throw ex; - } finally { this.serverConnection.SqlExecutionModes = executionMode; diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/RestoreOperation/RestoreDatabaseTaskDataObject.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/RestoreOperation/RestoreDatabaseTaskDataObject.cs index 0816e05e..3b226a95 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/RestoreOperation/RestoreDatabaseTaskDataObject.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/RestoreOperation/RestoreDatabaseTaskDataObject.cs @@ -12,7 +12,6 @@ using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts; using Microsoft.SqlTools.ServiceLayer.TaskServices; -using Microsoft.SqlTools.ServiceLayer.Utility; using Microsoft.SqlTools.Utility; using Microsoft.SqlTools.ServiceLayer.Connection; using System.Diagnostics; @@ -318,7 +317,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation catch(Exception ex) { Logger.Write(TraceEventType.Information, $"Failed to execute restore task. error: {ex.Message}"); - throw ex; + throw; } finally { diff --git a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/DataContainer.cs b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/DataContainer.cs index 9efa11f7..c03769de 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/DataContainer.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/DataContainer.cs @@ -5,21 +5,15 @@ using System; using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; using System.Data; using System.Globalization; using System.IO; -using System.Reflection; using System.Security; using System.Xml; -using System.Xml.Linq; using Microsoft.SqlServer.Management.Common; -using Microsoft.SqlServer.Management.Diagnostics; using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlTools.ServiceLayer.Connection; -using Assembly = System.Reflection.Assembly; namespace Microsoft.SqlTools.ServiceLayer.Management { @@ -773,22 +767,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Management if (site != null) { // see if service provider supports INodeInformation interface from the object explorer - try + // NOTE: we're trying to forcefully set connection information on the data container. + // If this code doesn't execute, then dc.Init call below will result in CDataContainer + // initializing its ConnectionInfo member with a new object contructed off the parameters + // in the XML doc [server name, user name etc] + IManagedConnection managedConnection = site.GetService(typeof(IManagedConnection)) as IManagedConnection; + if (managedConnection != null) { - // NOTE: we're trying to forcefully set connection information on the data container. - // If this code doesn't execute, then dc.Init call below will result in CDataContainer - // initializing its ConnectionInfo member with a new object contructed off the parameters - // in the XML doc [server name, user name etc] - IManagedConnection managedConnection = site.GetService(typeof(IManagedConnection)) as IManagedConnection; - if (managedConnection != null) - { - this.SetManagedConnection(managedConnection); - } - } - catch (Exception ex) - { - // keep the exception flowing - throw ex; + this.SetManagedConnection(managedConnection); } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs index 8da3b18b..642c71d2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs @@ -8,7 +8,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; -using System.Reflection; using System.Threading; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes; @@ -40,11 +39,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel string error = string.Format(CultureInfo.InvariantCulture, "Failed expanding oe children. parent:{0} error:{1} inner:{2} stacktrace:{3}", parent != null ? parent.GetNodePath() : "", ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace); Logger.Write(TraceEventType.Error, error); - throw ex; - } - finally - { + throw; } + return allChildren; } @@ -145,7 +142,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel string error = string.Format(CultureInfo.InvariantCulture, "Failed getting smo objects. parent:{0} querier: {1} error:{2} inner:{3} stacktrace:{4}", parent != null ? parent.GetNodePath() : "", querier.GetType(), ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace); Logger.Write(TraceEventType.Error, error); - throw ex; + throw; } } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/TaskServices/SmoScriptableOperationWithFullDbAccess.cs b/src/Microsoft.SqlTools.ServiceLayer/TaskServices/SmoScriptableOperationWithFullDbAccess.cs index 2f584d6c..d9789494 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TaskServices/SmoScriptableOperationWithFullDbAccess.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TaskServices/SmoScriptableOperationWithFullDbAccess.cs @@ -65,13 +65,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices hasAccessToDb = GainAccessToDatabase(); base.Execute(mode); } - catch (DatabaseFullAccessException databaseFullAccessException) + catch (DatabaseFullAccessException) { Logger.Write(TraceEventType.Warning, $"Failed to gain access to database. server|database:{ServerName}|{DatabaseName}"); - throw databaseFullAccessException; - } - catch - { throw; } finally