Skip to content

Commit cbe36fa

Browse files
authored
Merge pull request #3410 from Montro1981/SQL-Server-First-Responder-Kit_3409
#3409 Implemented a different check for the 'instant_file_initialization_enabled' column
2 parents 9661ea3 + abdd7be commit cbe36fa

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

sp_Blitz.sql

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8721,13 +8721,20 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
87218721
,@IFIReadDMVFailed bit = 0
87228722
,@IFIAllFailed bit = 0;
87238723

8724-
BEGIN TRY
8725-
/* See if we can get the instant_file_initialization_enabled column from sys.dm_server_services */
8726-
SET @StringToExecute = N'
8727-
SELECT @IFISetting = instant_file_initialization_enabled
8728-
FROM sys.dm_server_services
8729-
WHERE filename LIKE ''%sqlservr.exe%''
8730-
OPTION (RECOMPILE);';
8724+
/* See if we can get the instant_file_initialization_enabled column from sys.dm_server_services */
8725+
IF EXISTS
8726+
(
8727+
SELECT 1/0
8728+
FROM sys.all_columns
8729+
WHERE [object_id] = OBJECT_ID(N'[sys].[dm_server_services]')
8730+
AND [name] = N'instant_file_initialization_enabled'
8731+
)
8732+
BEGIN
8733+
/* This needs to be a "dynamic" SQL statement because if the 'instant_file_initialization_enabled' column doesn't exist the procedure might fail on a bind error */
8734+
SET @StringToExecute = N'SELECT @IFISetting = instant_file_initialization_enabled' + @crlf +
8735+
N'FROM sys.dm_server_services' + @crlf +
8736+
N'WHERE filename LIKE ''%sqlservr.exe%''' + @crlf +
8737+
N'OPTION (RECOMPILE);';
87318738

87328739
IF @Debug = 2 AND @StringToExecute IS NOT NULL PRINT @StringToExecute;
87338740
IF @Debug = 2 AND @StringToExecute IS NULL PRINT '@StringToExecute has gone NULL, for some reason.';
@@ -8736,14 +8743,13 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
87368743
@StringToExecute
87378744
,N'@IFISetting varchar(1) OUTPUT'
87388745
,@IFISetting = @IFISetting OUTPUT
8739-
END TRY
8740-
BEGIN CATCH
8741-
/* We couldn't get the instant_file_initialization_enabled column from sys.dm_server_services, fall back to read error log */
8742-
SET @IFIReadDMVFailed = 1;
8743-
END CATCH;
8744-
8745-
IF @IFIReadDMVFailed = 1
8746+
8747+
SET @IFIReadDMVFailed = 0;
8748+
END
8749+
ELSE
8750+
/* We couldn't get the instant_file_initialization_enabled column from sys.dm_server_services, fall back to read error log */
87468751
BEGIN
8752+
SET @IFIReadDMVFailed = 1;
87478753
/* If this is Amazon RDS, we'll use the rdsadmin.dbo.rds_read_error_log */
87488754
IF LEFT(CAST(SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS VARCHAR(8000)), 8) = 'EC2AMAZ-'
87498755
AND LEFT(CAST(SERVERPROPERTY('MachineName') AS VARCHAR(8000)), 8) = 'EC2AMAZ-'

0 commit comments

Comments
 (0)