From 87c56b35be090576ec30ab9fbfd86e5715ba2fbb Mon Sep 17 00:00:00 2001 From: eltonkerber <41969525+eltonkerber@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:41:53 -0300 Subject: [PATCH 1/3] Update DatabaseBackup.sql Fix error on logging information at SQL agent job using data domain boost "Msg 0, Sev 0, State 1: Unknown token received from SQL Server [SQLSTATE HY000] String data, right truncation [SQLSTATE 01004] Msg 16389, Sev 16, State 1: The connection is no longer usable because the server response for a previously executed statement was incorrectly formatted. [SQLSTATE 08S01]" --- DatabaseBackup.sql | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/DatabaseBackup.sql b/DatabaseBackup.sql index 60e4684..dd9791f 100644 --- a/DatabaseBackup.sql +++ b/DatabaseBackup.sql @@ -1,13 +1,10 @@ -SET ANSI_NULLS ON +SET ANSI_NULLS ON GO + SET QUOTED_IDENTIFIER ON GO -IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DatabaseBackup]') AND type in (N'P', N'PC')) -BEGIN -EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[DatabaseBackup] AS' -END -GO -ALTER PROCEDURE [dbo].[DatabaseBackup] + +CREATE PROCEDURE [dbo].[DatabaseBackup] @Databases nvarchar(max) = NULL, @Directory nvarchar(max) = NULL, @@ -3354,7 +3351,7 @@ BEGIN SET @CurrentCommandType = 'xp_create_subdir' - SET @CurrentCommand = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = dbo.xp_create_subdir N''' + REPLACE(@CurrentDirectoryPath,'''','''''') + ''' IF @ReturnCode <> 0 RAISERROR(''Error creating directory.'', 16, 1)' + SET @CurrentCommand = 'DECLARE @t TABLE (msg NVARCHAR(MAX)) DECLARE @returncode INT INSERT INTO @t (msg) DECLARE @ReturnCode int EXECUTE @ReturnCode = dbo.xp_create_subdir N''' + REPLACE(@CurrentDirectoryPath,'''','''''') + ''' IF @ReturnCode <> 0 RAISERROR(''Error creating directory.'', 16, 1)' EXECUTE @CurrentCommandOutput = dbo.CommandExecute @DatabaseContext = @CurrentDatabaseContext, @Command = @CurrentCommand, @CommandType = @CurrentCommandType, @Mode = 1, @DatabaseName = @CurrentDatabaseName, @LogToTable = @LogToTable, @Execute = @Execute SET @Error = @@ERROR @@ -3706,8 +3703,14 @@ BEGIN SET @CurrentDatabaseContext = 'master' SET @CurrentCommandType = 'emc_run_backup' - - SET @CurrentCommand = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = dbo.emc_run_backup ''' + /* + Fix for error + Error: Msg 0, Sev 0, State 1: Unknown token received from SQL Server [SQLSTATE HY000] + String data, right truncation [SQLSTATE 01004] + Msg 16389, Sev 16, State 1: The connection is no longer usable because the server response for a previously executed statement was incorrectly formatted. [SQLSTATE 08S01] + https://github.com/olahallengren/sql-server-maintenance-solution/issues/658 + */ + SET @CurrentCommand = 'DECLARE @t TABLE (msg NVARCHAR(MAX)) DECLARE @returncode INT INSERT INTO @t (msg) EXECUTE @ReturnCode = dbo.emc_run_backup ''' SET @CurrentCommand += ' -c ' + CASE WHEN @CurrentAvailabilityGroup IS NOT NULL THEN @Cluster ELSE CAST(SERVERPROPERTY('MachineName') AS nvarchar) END @@ -4082,4 +4085,3 @@ BEGIN END GO - From d1e89c26dd1b54d22251c0774117c56b6d918c90 Mon Sep 17 00:00:00 2001 From: eltonkerber <41969525+eltonkerber@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:44:24 -0300 Subject: [PATCH 2/3] Update DatabaseBackup.sql --- DatabaseBackup.sql | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/DatabaseBackup.sql b/DatabaseBackup.sql index dd9791f..f1ceddd 100644 --- a/DatabaseBackup.sql +++ b/DatabaseBackup.sql @@ -1,10 +1,14 @@ + SET ANSI_NULLS ON GO - SET QUOTED_IDENTIFIER ON GO - -CREATE PROCEDURE [dbo].[DatabaseBackup] +IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DatabaseBackup]') AND type in (N'P', N'PC')) +BEGIN +EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[DatabaseBackup] AS' +END +GO +ALTER PROCEDURE [dbo].[DatabaseBackup] @Databases nvarchar(max) = NULL, @Directory nvarchar(max) = NULL, @@ -4084,4 +4088,3 @@ BEGIN ---------------------------------------------------------------------------------------------------- END -GO From 983ee5ac3d2f330c8094138b78b1f541289fb62d Mon Sep 17 00:00:00 2001 From: eltonkerber <41969525+eltonkerber@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:44:36 -0300 Subject: [PATCH 3/3] Update DatabaseBackup.sql