尝试在另一个区域创建新的 SQL 数据库作为我们无法生成实例的主数据库的辅助地理副本时,我遇到了一些问题。本质上,我最终想要的是自动设置每个数据库的复制实例,该实例在我们的生产系统中可用,但在另一个区域中可用。
我无法找到任何关于如何创建 SQL 实例的示例,如果有任何关于如何通过 SDK 处理它的提示,我将不胜感激。到目前为止,我已经成功运行了以下测试代码:
string fromResourceGroupName = "";
string fromSubscriptionId = "";
string fromSqlServerName = "";
string targetResourceGroupName = "";
string targetSubscriptionId = "";
string targetSqlServerName = "";
DefaultAzureCredential credentials = new(includeInteractiveCredentials: true);
ArmClient client = new(credentials);
SubscriptionCollection subs = client.GetSubscriptions();
// We want to create a secondary copy from these databases
SubscriptionResource fromSubscription = subs.Get(fromSubscriptionId);
ResourceGroupCollection fromResourceGroups = fromSubscription.GetResourceGroups();
ResourceGroupResource fromResourceGroup = await fromResourceGroups.GetAsync(fromResourceGroupName);
SqlServerResource fromSqlServer = fromResourceGroup.GetSqlServer(fromSqlServerName).Value;
SqlDatabaseCollection fromDatabaseCollection = fromSqlServer.GetSqlDatabases();
// To this SQL server instance
SubscriptionResource targetSubscription = subs.Get(targetSubscriptionId);
ResourceGroupCollection targetResourceGroups = targetSubscription.GetResourceGroups();
ResourceGroupResource targetResourceGroup = await targetResourceGroups.GetAsync(targetResourceGroupName);
SqlServerResource targetSqlServer = targetResourceGroup.GetSqlServer(targetSqlServerName).Value;
foreach (SqlDatabaseResource? sourceIter in fromDatabaseCollection)
{
// What to put here?
}