c# - 如何在 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 文档非常稀少。
解决方案
感觉就像我在这里需要一个 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 门户检查
推荐阅读
- powershell - 将 PSCustomObject 添加到数组会产生错误,但在 Visual Studio Code 中调试代码时可以正常工作
- python - 加入两个类对象 - Python
- javascript - 如何解析时间'HH:MM:SS'并在Chart.js中每分钟在xAxis上显示步骤
- ckeditor - Connections 5 CR6 中未应用 CKEditor 的自定义
- symfony - Payum Bundle Symfony 事件
- sql - Oracle SQL - 在自由文本叙述中编辑除了最后四位数字之外的多次出现
- python - 如果缺少某些键和值,如何填写列表列表?
- c++ - 寻找可以将整数表示为唯一自然数的 n 次方之和的方法。给出错误输出的代码
- jdbc - Clojure jdbc对sum的奇怪响应
- mysql - perl dbi mysql - 值精度