diff --git a/src/sql/workbench/contrib/backup/browser/backupActions.ts b/src/sql/workbench/contrib/backup/browser/backupActions.ts index fdd105f25e..b053cf1b75 100644 --- a/src/sql/workbench/contrib/backup/browser/backupActions.ts +++ b/src/sql/workbench/contrib/backup/browser/backupActions.ts @@ -19,6 +19,9 @@ import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilit import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile'; export const BackupFeatureName = 'backup'; +export const backupIsPreviewFeature = localize('backup.isPreviewFeature', "You must enable preview features in order to use backup"); +export const backupNotSupportedOutOfDBContext = localize('backup.commandNotSupportedForServer', "Backup command is not supported outside of a database context. Please select a database and try again."); +export const backupNotSupportedForAzure = localize('backup.commandNotSupported', "Backup command is not supported for Azure SQL databases."); export function showBackup(accessor: ServicesAccessor, connection: IConnectionProfile): Promise { const backupUiService = accessor.get(IBackupUiService); @@ -43,7 +46,7 @@ export class BackupAction extends Task { const configurationService = accessor.get(IConfigurationService); const previewFeaturesEnabled = configurationService.getValue<{ enablePreviewFeatures: boolean }>('workbench').enablePreviewFeatures; if (!previewFeaturesEnabled) { - return accessor.get(INotificationService).info(localize('backup.isPreviewFeature', "You must enable preview features in order to use backup")); + return accessor.get(INotificationService).info(backupIsPreviewFeature); } const connectionManagementService = accessor.get(IConnectionManagementService); @@ -55,17 +58,20 @@ export class BackupAction extends Task { if (profile) { const serverInfo = connectionManagementService.getServerInfo(profile.id); if (serverInfo && serverInfo.isCloud && profile.providerName === mssqlProviderName) { - return accessor.get(INotificationService).info(localize('backup.commandNotSupported', "Backup command is not supported for Azure SQL databases.")); + return accessor.get(INotificationService).info(backupNotSupportedForAzure); } if (!profile.databaseName && profile.providerName === mssqlProviderName) { - return accessor.get(INotificationService).info(localize('backup.commandNotSupportedForServer', "Backup command is not supported in Server Context. Please select a Database and try again.")); + return accessor.get(INotificationService).info(backupNotSupportedOutOfDBContext); } } const capabilitiesService = accessor.get(ICapabilitiesService); const instantiationService = accessor.get(IInstantiationService); profile = profile ? profile : new ConnectionProfile(capabilitiesService, profile); + if (!profile.databaseName) { + return accessor.get(INotificationService).info(backupNotSupportedOutOfDBContext); + } return instantiationService.invokeFunction(showBackup, profile); } } diff --git a/src/sql/workbench/contrib/restore/browser/restoreActions.ts b/src/sql/workbench/contrib/restore/browser/restoreActions.ts index dc23c73acb..661fbbe0da 100644 --- a/src/sql/workbench/contrib/restore/browser/restoreActions.ts +++ b/src/sql/workbench/contrib/restore/browser/restoreActions.ts @@ -24,6 +24,10 @@ export function showRestore(accessor: ServicesAccessor, connection: IConnectionP } export const RestoreFeatureName = 'restore'; +export const restoreIsPreviewFeature = localize('restore.isPreviewFeature', "You must enable preview features in order to use restore"); +export const restoreNotSupportedOutOfContext = localize('restore.commandNotSupportedOutsideContext', "Restore command is not supported outside of a server context. Please select a server or database and try again."); +export const restoreNotSupportedForAzure = localize('restore.commandNotSupported', "Restore command is not supported for Azure SQL databases."); + export class RestoreAction extends Task { public static readonly ID = RestoreFeatureName; @@ -44,7 +48,7 @@ export class RestoreAction extends Task { const configurationService = accessor.get(IConfigurationService); const previewFeaturesEnabled: boolean = configurationService.getValue<{ enablePreviewFeatures: boolean }>('workbench').enablePreviewFeatures; if (!previewFeaturesEnabled) { - return accessor.get(INotificationService).info(localize('restore.isPreviewFeature', "You must enable preview features in order to use restore")); + return accessor.get(INotificationService).info(restoreIsPreviewFeature); } let connectionManagementService = accessor.get(IConnectionManagementService); @@ -56,13 +60,16 @@ export class RestoreAction extends Task { if (profile) { const serverInfo = connectionManagementService.getServerInfo(profile.id); if (serverInfo && serverInfo.isCloud && profile.providerName === mssqlProviderName) { - return accessor.get(INotificationService).info(localize('restore.commandNotSupported', "Restore command is not supported for Azure SQL databases.")); + return accessor.get(INotificationService).info(restoreNotSupportedForAzure); } } const capabilitiesService = accessor.get(ICapabilitiesService); const instantiationService = accessor.get(IInstantiationService); profile = profile ? profile : new ConnectionProfile(capabilitiesService, profile); + if (!profile.serverName) { + return accessor.get(INotificationService).info(restoreNotSupportedOutOfContext); + } return instantiationService.invokeFunction(showRestore, profile); } }