SQL 使用 .Net 的 Azure 管理库创建具有 Azure 访问权限的服务器

SQL Server with Azure access creation with Azure Management Libraries for .Net

我使用 .Net 的 Azure 管理库创建了 azure SQL 服务器,我需要添加防火墙规则以允许 Azure 服务访问新服务器(如门户中的开关)。我目前这样创建服务器

sqlServer = Azure.SqlServers
                    .Define(serverName)
                    .WithRegion(region)
                    .WithExistingResourceGroup(resourceGroup.Name)
                    .WithAdministratorLogin(AppSettings.SqlServerAdminUser)
                    .WithAdministratorPassword(AppSettings.SqlServerAdminPassword)
                    .WithNewFirewallRule("xxx.xxx.xxx.xxx")
                    .WithNewFirewallRule("xxx.xxx.xxx.xxx", "xxx.xxx.xxx.xxx")
                    .WithNewElasticPool(poolName, elasticPoolEdition, databaseName)
                    .Create();

是否有任何我没有找到的选项通常允许 Azure 服务访问此 SQL 服务器?

谢谢!

Is there any option I did not find to generally allow Azure services to access this SQL server?

因此,API 级别没有允许 Azure 服务访问 SQL 服务器的设置。幕后发生的事情是,当您想通过门户设置此设置时,会为您创建一个带有 0.0.0.0 IP 地址的防火墙规则。

由于 0.0.0.0 并不是真正的 IP 地址,Azure API 将其视为允许访问 Azure 服务的特殊情况。

这也是您需要做的。

请尝试以下代码:

sqlServer = Azure.SqlServers
                    .Define(serverName)
                    .WithRegion(region)
                    .WithExistingResourceGroup(resourceGroup.Name)
                    .WithAdministratorLogin(AppSettings.SqlServerAdminUser)
                    .WithAdministratorPassword(AppSettings.SqlServerAdminPassword)
                    .WithNewFirewallRule("0.0.0.0") // Allow access to Azure Services
                    .WithNewFirewallRule("xxx.xxx.xxx.xxx", "xxx.xxx.xxx.xxx")
                    .WithNewElasticPool(poolName, elasticPoolEdition, databaseName)
                    .Create();

您应该会看到您的 Azure 服务将能够访问此 SQL 服务器。

当你想启用 allow Azure services to access server 选项时,当你创建一个新的 Azure SQL 服务器时,它实际上会创建一个新的防火墙规则,默认名称:“AllowAllWindowsAzureIp”与 startIpAddress0.0.0.0endIpAddress: 0.0.0.0

我认为基于上面的默认防火墙规则属性,它应该将 startIpAddress 和 endIpAddress 定义为 0.0.0.0

sqlServer = Azure.SqlServers
                    .Define(serverName)
                    .WithRegion(region)
                    .WithExistingResourceGroup(resourceGroup.Name)
                    .WithAdministratorLogin(AppSettings.SqlServerAdminUser)
                    .WithAdministratorPassword(AppSettings.SqlServerAdminPassword)
                    .WithNewFirewallRule("0.0.0.0", "0.0.0.0")
                    .WithNewElasticPool(poolName, elasticPoolEdition, databaseName)
                    .Create();