diff --git a/src/SqlBackupTools/Restore/Native/NativeRestoreMethod.cs b/src/SqlBackupTools/Restore/Native/NativeRestoreMethod.cs index 47bc16f..3d65a68 100644 --- a/src/SqlBackupTools/Restore/Native/NativeRestoreMethod.cs +++ b/src/SqlBackupTools/Restore/Native/NativeRestoreMethod.cs @@ -105,7 +105,10 @@ private async Task InternalFullDiffLogAsync(RestoreItem item, bool st forceRestoreFull = true; try { - await sqlConnection.ExecuteAsync($"ALTER DATABASE [{item.Name}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE", commandTimeout: _state.RestoreCommand.Timeout); + if (_state.ActualDbs.TryGetValue(item.Name, out var databaseInfo) && databaseInfo.State != DatabaseState.RESTORING) + { + await sqlConnection.ExecuteAsync($"ALTER DATABASE [{item.Name}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE", commandTimeout: _state.RestoreCommand.Timeout); + } await sqlConnection.ExecuteAsync($"DROP DATABASE [{item.Name}]", commandTimeout: _state.RestoreCommand.Timeout); await sqlConnection.ExecuteAsync($"EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'{item.Name}'", commandTimeout: _state.RestoreCommand.Timeout); }