如何在Azure fluent API for SQL Server中为现有数据库设置服务器级别目标(定价层)?

时间:2018-05-19 12:15:18

标签: c# azure azure-sql-database fluent azure-management-api

如何在Azure fluent API for SQL Server中为现有Azure SQL数据库设置服务器级别目标(定价层)?

我使用的是Microsoft.Azure.Management.Sql.Fluent,版本1.10.0,这是截至今天的最新版本。

Microsoft提供的此示例代码创建Azure SQL数据库,然后设置其服务器级别

        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();

如何设置现有数据库的服务级别?

我能得到的最接近的是

        .WithAdministratorPassword("mypassword")

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

不会抛出异常但也不会执行任何操作。数据库的服务级别不会改变。

感觉我在这里需要一个Apply(),但这不是一个选择。

Azure Fluent API for SQL Server上的Microsoft文档非常稀疏。

1 个答案:

答案 0 :(得分:0)

  

感觉我在这里需要一个Apply(),但这不是一个选择。

你几乎得到了答案。根据我的测试,它需要.Apply()

我用以下代码测试它。并从天蓝色门户网站查看。

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

从Azure门户检查

enter image description here