1

How to set a server level objective (pricing tier) for an existing Azure SQL database in Azure fluent API for SQL Server?

I am using Microsoft.Azure.Management.Sql.Fluent, version 1.10.0, which is latest as of today.

This sample code provided by Microsoft creates an Azure SQL database, then sets its server level

        var azCreds = SdkContext.AzureCredentialsFactory.FromFile(filePath);

        var azure = Azure.Configure()
            .Authenticate(azCreds)
            .WithSubscription("mysubscriptionid");

        var sqlServer =

                azure.SqlServers.Define("existingsqlserverid")
                .WithRegion(Region.USEast)
                .WithExistingResourceGroup("Default-SQL-EastUS")
                .WithAdministratorLogin("mylogin")
                .WithAdministratorPassword("mypassword")

               .Create()
               .Databases
               .Define("NewDbName")
               .Create()
               .Update()

               .WithEdition(DatabaseEditions.Standard)
               .WithServiceObjective(ServiceObjectiveName.S1)
               .Apply();

How do I set the service level of an existing db?

The closest I can seem to get is

        .WithAdministratorPassword("mypassword")

        .DefineDatabase("OldDbName")
        .WithEdition(DatabaseEditions.Standard)
        .WithServiceObjective(ServiceObjectiveName.S2);

which doesn't throw exceptions but also doesn't do anything. The service level of the db doesn't change.

It feels like I need an Apply() here, but that's not an option.

The Microsoft doc on the Azure Fluent API for SQL Server is very sparse.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
MindModel
  • 822
  • 1
  • 10
  • 22

1 Answers1

1

It feels like I need an Apply() here, but that's not an option.

You are almost getting the answer. Based on my test, it needs .Apply().

I test it with following code. And also check it from azure portal.

var credFile = @"file path"; // example: c:\tom\auth.txt
var resourceGroup = "resource group name";
var azureSQLName = "Azure sql server name"; //just name of the Azure sql server such as tomdemo
var databaseName = "database name";
var credentials = SdkContext.AzureCredentialsFactory.FromFile(credFile);
var azure = Azure
            .Configure()
            .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
            .Authenticate(credentials)
            .WithDefaultSubscription();

var updateAzureDatabasePriceTier = azure
            .SqlServers
            .GetByResourceGroup(resourceGroup, azureSQLName)
            .Databases.Get(databaseName)
            .Update()
            .WithEdition(DatabaseEditions.Standard)
            .WithServiceObjective(ServiceObjectiveName.S0)
            .Apply();

enter image description here

Check from the Azure portal

enter image description here

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47