A Gotcha when using the Azure SQL Server IaaS

I am currently working on moving our company product to Azure Cloud.  In this post, I am going to share a gotcha I came across with our Azure SQL Server IaaS.

For our product, we have to use Azure SQL Server IaaS for a few reasons:  The way our SSIS projects have been developed like: using DTC,  Office drivers and file operations; We have a few cross-database queries within our Store procedures; A fair bit of automation using SQL Server Agent.

I have been helping to create our Azure infrastructure using Terraform and ARM templates to build our Azure SQL Server IaaS.  Getting our SQL Server made was reasonably straightforward.  The gotcha was when we looked at the results: The SQL Server agent was installed but not started and the start-up for the service set as manual.  As mentioned, we use SQL Server agent to automation a few processes within our product; this wasn't the desired state also I must admit I have forgotten that this is SQL Server Agent default install method.

To have SQL Server agent to have the start-up of the service set to automatic and started after the provisioning.  You can use the virtual machine custom script extension with a PowerShell script.

When provisioning an Azure SQL Server IaaS, you first need to create a virtual machine,  then install the SQL Server extension.  To use the custom script extension to automate the SQL Server Agent a dependency on the SQL Server extension has to be stated.  The following is ARM example of how to create the dependency: 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
"resources": [
{
"name": "vmsqlserver/sqlserver",
"type": "Microsoft.SqlVirtualMachine/SqlVirtualMachines",
"apiVersion": "2017-03-01-preview",
"location": "[resourceGroup().location]"
......
},
{
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "apiVersion": "2015-06-15",
            "name": "vmsqlserver/CustomScriptExtension",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                " vmsqlserver/sqlserver "
            ],
......
            }
        }
    ]

The following is the PowerShell script to the set the service start-up and to start the services:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ServiceName = 'SQLSERVERAGENT'
$SQLServerAgentSerivce = Get-Service -Name $ServiceName
	
if ($SQLServerAgentSerivce.Status -eq [System.ServiceProcess.ServiceControllerStatus]::Stopped) 
{ 
    $SQLServerAgentSerivce.Start() 
}

if ($SQLServerAgentSerivce.StartType -ne [System.ServiceProcess.ServiceStartMode]::Automatic) 
{ 
    Set-Service -Name $ServiceName -StartupType Automatic 
}

Comments

Popular posts from this blog

Azure SQL Server IaaS SSIS: A required privilege is not held by the client

SSIS File handle leak in For Each Loop

Cannot update a database that has been registered as a data-tier application