Set service levels when creating an Azure SQL database from VS C #

Is it possible to set the service levels of Microsoft Azure SQL Database when creating a new database from Visual Studio in C #? Currently, I can connect to the Azure SQL server and create the table without problems, but for some reason (maybe by default Microsoft) the databases will be created on the Internet, which is the service level that will be deleted. I would like the default service levels to be either Basic, Standard, or Premium, depending on the needs.

What I have found so far is when I call this method Database.Initialize (true) <- EF http://msdn.microsoft.com/en-us/library/system.data.entity.database.initialize (v = vs.113) .aspx It will create a database and configure it to the web service level.

+5
source share
2 answers

With Azure SQL v12, you can specify SKUs. Example:

var dbCreationCmd = $"CREATE DATABASE [{databaseName}] (MAXSIZE={maxSize}," + $"EDITION='{edition}'," + $"SERVICE_OBJECTIVE='{serviceObjective}')"; // With Azure SQL db V12, database creation TSQL became a sync process. // So we need a 10 minutes command timeout ExecuteNonQuery(connectionString, dbCreationCmd, commandTimeout: 600); 
+1
source

As mentioned by Simon, SQL data layers can only be executed after the database is provided.

From Powershell, here is a feature that can be called database post-provisioning

 Function Update-DatabaseServiceTier { Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)][ValidateNotNullOrEmpty()] [String]$databasename, [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=1)][ValidateNotNullOrEmpty()] [String]$PerformanceLevel, [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=2)][ValidateNotNullOrEmpty()] [String]$Edition, [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=3)][ValidateNotNullOrEmpty()] [String]$MaxSize, [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=4)][ValidateNotNullOrEmpty()] [String]$SQLServerName, [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=5)][ValidateNotNullOrEmpty()] [String]$userId, [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=6)][ValidateNotNullOrEmpty()] [String]$password ) # Get current Database Details $DatabaseDetails = Get-AzureSqlDatabase -ServerName $SQLServerName -DatabaseName $databasename -ErrorAction Stop -WarningAction SilentlyContinue $currentEdition = $DatabaseDetails.Edition $currentSize = $DatabaseDetails.MaxSizeGB if (($currentEdition -ne $Edition) -or ($currentSize -ne $MaxSize)) { Write-Verbose " Upgrading the Database Edition - Database Size" # Set SQL Server Connection Context $server = Get-AzureSqlDatabaseServer $SQLServerName -ErrorAction Stop -WarningAction SilentlyContinue $servercredential = New-object System.Management.Automation.PSCredential($userId, ($password | ConvertTo-SecureString -asPlainText -Force)) $ctx = $server | New-AzureSqlDatabaseServerContext -Credential $serverCredential $db = Get-AzureSqlDatabase $ctx –DatabaseName $databasename -ErrorAction Stop -WarningAction SilentlyContinue $PL = Get-AzureSqlDatabaseServiceObjective -Context $ctx -ServiceObjectiveName $PerformanceLevel -ErrorAction Stop -WarningAction SilentlyContinue # Update SQL Server Properties (Service Objective, Edition and Size) Set-AzureSqlDatabase -ConnectionContext $ctx –Database $db -ServiceObjective $PL -Edition $Edition -MaxSizeGB $MaxSize -Force -ErrorAction Stop -WarningAction SilentlyContinue } else { Write-Verbose "" Write-Verbose " Database Edition and Size upto date!!" } } 
0
source

Source: https://habr.com/ru/post/1206594/


All Articles