Category Archives: SQL Server

Finding Your SSRS License Key on an Azure VM

A quick note today. I was installing an Azure VM with SQL Server, and the Reporting Services service is not part of the default install. You can still install reporting services but you’ll either need to copy the installer onto your new VM or run the installation media which can be found on the C drive:

Installation Media: C:\SQLServerFull

Either way you’ll hit a wall where it asks you for the installation key. This is stored in the x64 directory of the install media in a file called Default Setup:

Report Services Key Location: C:\SQLServerFull\x64

Just look for the PID under options and paste that into the installer and you are done. Hope that’s helpful.

SQL Saturday Auckland

Time to polish off the JAFA jokes for another year, SQL Saturday Auckland is just 2 days away. Check out the lineup at:

https://www.sqlsaturday.com/866/

This year I’ll be taking attendees over the types of Encryption that are available within SQL Server, and more importantly – why they should care. If previous experience is anything to go by I don’t expect a huge turnout as Security sessions in general are not that popular at these types of events. That’s why I’ve pitched this session at absolute beginners to the world of protecting their SQL Data, because I believe it’s critical that we all stop hoping that SQL Security is someone elses problem, and accept that we all need to be a part of the security chain.

If you are in Auckland on Saturday, and your firm uses SQL Servers to store you critical data – I really encourage you to come along to this free training event. I see Reza has posted we are expecting up to 380 people to attend, making this the largest free IT training event in the country. Great job once again #SQLSATAUCKLAND team.

SPAM, SPAM, SQL and SPAM

Because I keep having to rewrite my scripts every time I need to have a spammy procedure to just be doing something, and because 10 minutes is 10 minutes – here’s my spamroller.

First create the table:

CREATE DATABASE [SPAMSPAMEGGSANDSPAM]
GO
USE [SPAMSPAMEGGSANDSPAM]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SpamSpamSpam](
	[spam_id] [int] IDENTITY(1,1) NOT NULL,
	[Time_Entered] [datetime] NOT NULL,
	[TypeOfSpam] [varchar](100) NOT NULL
) ON [PRIMARY]
GO

Then create the job to populate it and mess it up every 10 seconds.

USE [msdb]
GO

/****** Object:  Job [LovelySpam]    Script Date: 1/07/2019 2:45:57 PM ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object:  JobCategory [[Uncategorized (Local)]]    Script Date: 1/07/2019 2:45:58 PM ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'LovelySpam', 
		@enabled=1, 
		@notify_level_eventlog=0, 
		@notify_level_email=0, 
		@notify_level_netsend=0, 
		@notify_level_page=0, 
		@delete_level=0, 
		@description=N'To simulate a little activity on the database this job enters Spam into a table.  The job inserts a new row, updates a random existing one and reads everything in the table every 10 seconds.  Note for future reviewers - we may need to reseed the database in about 680 years.', 
		@category_name=N'[Uncategorized (Local)]', 
		@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Bacon Eggs and Spam]    Script Date: 1/07/2019 2:46:00 PM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Bacon Eggs and Spam', 
		@step_id=1, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'declare @start as DateTime;
declare @randomnumber as int = cast(rand() * 9000 AS INT)+999
declare @randomtext as varchar(100) = cast(@randomnumber as varchar(100))+''!''
set @start = getdate()


SET @randomtext=replace(@randomtext,''1'',''spam, '')
SET @randomtext=replace(@randomtext,''0'',''sausage, '')
SET @randomtext=replace(@randomtext,''2'',''spam, '')
SET @randomtext=replace(@randomtext,''3'',''baked beans, '')
SET @randomtext=replace(@randomtext,''4'',''spam, '')
SET @randomtext=replace(@randomtext,''5'',''spam, '')
SET @randomtext=replace(@randomtext,''6'',''eggs, '')
SET @randomtext=replace(@randomtext,''7'',''spam, '')
SET @randomtext=replace(@randomtext,''8'',''bacon, '')
SET @randomtext=replace(@randomtext,''9'',''spam, '')
SET @randomtext=replace(@randomtext,'', !'','' and spam.'')

set @randomnumber=CAST(RAND() * 9 AS INT)+1

insert into dbo.SpamSpamSpam(Time_Entered,TypeOfSpam) values(@start,@randomtext)
', 
		@database_name=N'SPAMSPAMEGGSANDSPAM', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Spam Spam and Eggs]    Script Date: 1/07/2019 2:46:18 PM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Spam Spam and Eggs', 
		@step_id=2, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'Select * from dbo.SpamSpamSpam', 
		@database_name=N'SPAMSPAMEGGSANDSPAM', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Spam Sausage Spam Spam and Eggs with Spam]    Script Date: 1/07/2019 2:46:18 PM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Spam Sausage Spam Spam and Eggs with Spam', 
		@step_id=3, 
		@cmdexec_success_code=0, 
		@on_success_action=1, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'--Update a random row
--Note - this step should get slower the bigger the table gets.  By design.

declare @start as DateTime;
declare @randomrow as int = cast(rand() * 9000 AS INT)+999
declare @randomtext as varchar(100) = cast(@randomrow as varchar(100))+''!''
set @start = getdate()


SET @randomtext=replace(@randomtext,''1'',''spam, '')
SET @randomtext=replace(@randomtext,''0'',''sausage, '')
SET @randomtext=replace(@randomtext,''2'',''spam, '')
SET @randomtext=replace(@randomtext,''3'',''baked beans, '')
SET @randomtext=replace(@randomtext,''4'',''spam, '')
SET @randomtext=replace(@randomtext,''5'',''spam, '')
SET @randomtext=replace(@randomtext,''6'',''eggs, '')
SET @randomtext=replace(@randomtext,''7'',''spam, '')
SET @randomtext=replace(@randomtext,''8'',''bacon, '')
SET @randomtext=replace(@randomtext,''9'',''spam, '')
SET @randomtext=replace(@randomtext,'', !'','' and spam.'')

select top 1 @randomrow=spam_id from dbo.SpamSpamSpam order by newid()

select @randomrow, @randomtext
update dbo.SpamSpamSpam set TypeOfSpam = @randomtext, Time_Entered = @start where spam_id=@randomrow', 
		@database_name=N'SPAMSPAMEGGSANDSPAM', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'Run it heaps', 
		@enabled=1, 
		@freq_type=4, 
		@freq_interval=1, 
		@freq_subday_type=2, 
		@freq_subday_interval=10, 
		@freq_relative_interval=0, 
		@freq_recurrence_factor=0, 
		@active_start_date=20190701, 
		@active_end_date=99991231, 
		@active_start_time=0, 
		@active_end_time=235959, 
		@schedule_uid=N'ea695562-ea40-4536-8164-ea8c2afce7c4'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO


Once you’ve run both bits of code you’ll be the proud owner of a rather boring agent job that runs every 10 seconds, adds a row to a table and updates another random one. Add loops, more jobs and bigger fields depending on your purposes for randomly filling a table.

What’s the point? Well, this particular usecase I wanted to test the effects of statistics as rows changed. I’ve used the same type of procedure for measuring compression and testing isolation levels. It’s amazing how often I find myself rewriting this type of job just because I need to be testing against a database that pretends to have actual connections to it.

Enjoy.

SQL Saturday South Island

I’m honored to be speaking at the next SQL Saturday in Christchurch on June 8th. Check out the link below:

https://www.sqlsaturday.com/831/eventhome.aspx

After taking most of last year off from speaking at these events, I’m looking forward to getting back into it, not to mention catching up with a lot of people I haven’t seen for a while. If you are in Christchurch that weekend be sure to come along.

Hackathon to help Support The Canterbury Muslim Community Trust

I wanted to make sure everyone was aware of this great Initiative to support the Canterbury Muslim Community Trust. After the events of March I think a lot of people are left wondering what they can do to show their support of those effected and to help out. Steve Knutson and Hamish Watson have done a great job of pulling this event together.

Unfortunately I am not going to be able to make it down to Christchurch for this weekend, but I do hope that the extra link helps:

https://techweek.co.nz/whats-on/2019/hackathon-to-help-support-the-canterbury-muslim-community-trust-cmct-460/

A Personal Weight Loss Milestone

2019 has gotten off to a very busy start on the work front, but on the personal front it has been more of the same. I’ve just been putting one foot infront of the other, and I’ve been doing it alot. As a result I’ve dropped 10% of my body weight in the last 3 months.

Back in October 2018 I had a couple of health issues. The most obvious was a back injury which cost me a number of days off work and is still troubling me today when I move in the wrong way. Less obvious was a brief chest pain I experienced which I found a bit scary. My mother has suffered multiple heart attacks and my Grandfather died from one. While this issue was not a heart attack, it was scary. I knew I was overweight and working in IT I live a lifestyle which is mostly sedentary.

But while I wasn’t moving much, things were certainly very busy at work. Quite simply I felt that I didn’t have time to fit exercise into my life. I kept thinking “You can start getting fit when things aren’t so crazy” or “You can work on your health when this project is out of the way”. The only problem is, things are always crazy, and finishing one project just means you’ll have another one take it’s place.

So I took some advice from the Arnold Schwarzenegger when he was asked how he fit everything in. “Sleep faster”. I got a fitbit and resolved to getting up at 5 o’clock each morning and walking for a couple of hours. I still can’t run because it jars my back, but if I can walk, I walk. After a while walking every morning a few of those fitbit challenges seemed within reach and I found myself walking in the evenings at night. It’s a great way to unwind, get exercise and fresh air, and as a nice side effect I have slept very soundly since I started doing this.

Looking back at my history the first day I logged steps was November 21st when I was 98.8kg. Today I dropped under 90kg for the first time, weighing in at 89.6kg. That means dropping a kg roughly every 9 days, which was a bit slower than the 1 per week I was targeting, but still something I’m pretty happy about.

Why is this on a blog which is mostly technical and work related? Quite simply I’ve come to realize that everything starts with looking after yourself. I encourage everyone else to challenge their belief about how much free time they have to fit exercise into your schedule. My perspective has been flipped on its head and now everything else needs to fit around my walking, not the other way around.

How To Get a Free Azure Database

I’ve been doing some testing on Azure database over the past few weeks. Obviously when you move to databases being used as a service you need to pay to get this service, but I did find a nice little workaround that unlocks the “free tier” for SQL Database.

The process is outlined below, but the TLDR version is – create a “WebApp + SQL” in the free tier and the database becomes free. There are some downsides to this of course – the free tier is limited to 5DTU and 32MB size, and it vanishes after a year. But for playing around those values should be fine – and if you need more than that it gives you a good marker for how much Azure Database will cost you, because don’t forget what you are paying based on in Azure DB.

To get your free Azure Database Click on “Create a Resource” and search for “WebApp + SQL”. Select it then click create and you’ll see something like this:

The elusive “Free” tier.

The free tier can be selected from within the Dev\Test toolset:

Free is good.

Then when you select the information for your database the super secret free Azure Database Tier has been unlocked.

Oh look…a secret thing.

Please remember the limits on that free database:

It expires after 365 days

It has only 5DTU

It cannot be larger than 32MB.

Easily enough to run my new CRM on…