microsoft / tigertoolbox

Toolbox repository for Tiger team
http://aka.ms/sqlserverteam
Other
1.48k stars 740 forks source link

Check_BP_Servers fails with NVARCHAR database names #60

Closed BrentOzar closed 6 years ago

BrentOzar commented 6 years ago

Not urgent at all, just filing because I'd heard Pedro talking about the script, figured I'd give it a shot.

Steps to repro:

CREATE DATABASE [¯\_(ツ)_/¯];
CREATE DATABASE [ಠ_ಠ];
GO

Then run Check_BP_Servers, and it fails with errors like:

|-Starting Database Information
  |-Building DB list
  |-Applying specific database scope list, if any
Msg 50000, Level 16, State 1, Line 1349
Database Information subsection - Error raised in TRY block. Database '?_?' does not exist. Make sure that the name is entered correctly.
Msg 50000, Level 16, State 1, Line 1349
Database Information subsection - Error raised in TRY block. Database '¯\_(?)_/¯' does not exist. Make sure that the name is entered correctly.
  |-Starting Storage analysis for In-Memory OLTP Engine
Msg 50000, Level 16, State 1, Line 1559
Storage analysis for In-Memory OLTP Engine subsection - Error raised in TRY block. Database '?_?' does not exist. Make sure that the name is entered correctly.
Msg 50000, Level 16, State 1, Line 1559
Storage analysis for In-Memory OLTP Engine subsection - Error raised in TRY block. Database '¯\_(?)_/¯' does not exist. Make sure that the name is entered correctly.

Root cause looks like the @dbname parameters being varchar, because this won't work:

DECLARE @test VARCHAR(50);
SET @test = '¯\_(ツ)_/¯';
SELECT @test

Result: ¯_(?)_/¯

Environment: 14.0.1000.169, Windows, case-sensitive default collation.

BrentOzar commented 6 years ago

varchar-everywhere

There's VARCHAR everywhere in here for database names, schema names, and index names. I fixed enough to where it'd run without erroring out, although just at a glance I think some of the results still have the wrong data in it.

For your testing environment, I'd add a database like this:

CREATE DATABASE [Database_¯\_(ツ)_/¯];
GO
USE [Database_¯\_(ツ)_/¯];
GO
CREATE SCHEMA [Schema_¯\_(ツ)_/¯];
CREATE TABLE [Schema_¯\_(ツ)_/¯].[Table_¯\_(ツ)_/¯] ([Field_¯\_(ツ)_/¯] INT IDENTITY(1,1) PRIMARY KEY CLUSTERED, Stuffing NVARCHAR(100));
CREATE NONCLUSTERED INDEX [Index_¯\_(ツ)_/¯] ON [Schema_¯\_(ツ)_/¯].[Table_¯\_(ツ)_/¯] ([Field_¯\_(ツ)_/¯]);
INSERT INTO [Schema_¯\_(ツ)_/¯].[Table_¯\_(ツ)_/¯] (Stuffing)
  SELECT TOP 100 name
  FROM sys.all_objects;
GO

Then if you ever see errors about database, schema, table, or index ¯_(?)_/¯ not existing, you'll know there's a varchar problem.

pmasl commented 6 years ago

Thanks Brent, fixing now.