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

问题描述

如何在 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 文档非常稀少。

标签: c#azureazure-sql-databasefluentazure-management-api

解决方案


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

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

我用下面的代码测试它。还可以从 azure 门户网站进行检查。

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

在此处输入图像描述

从 Azure 门户检查

在此处输入图像描述


推荐阅读