azure - Azure Powershell - 无法将子网设置添加到数据库
问题描述
我正在尝试使用 Azure Az 模块向 SQL Server 添加子网。我正在使用的命令是
New-AzSqlServerVirtualNetworkRule -VirtualNetworkRuleName "newvnetrule1" -ServerName $sqlServer.ServerName -ResourceGroupName $sqlServer.ResourceGroupName -VirtualNetworkSubnetId $newsubnetId -ErrorAction Stop
我得到一个例外说:
The client with object id does not have permission to perform this action
对象 id 属于 name 的 SPN Azure SQL Virtual Network to Network Resource Provider
。
我在使用 ARM 模板配置 cosmos db 帐户时遇到了完全相同的问题,只是这次错误的 SPN 是Azure Cosmos DB Virtual Network to Network Resource Provider
任何人都可以对此有所了解吗?以前可以正常工作的相同代码。所有服务也都为子网注册
解决方案
角色就够了,Owner
我这边测试一下,效果很好。
$virtualNetworkSubnetId = "/subscriptions/xxxxxxx/resourceGroups/joynet/providers/Microsoft.Network/virtualNetworks/joysqlnet/subnets/default"
New-AzSqlServerVirtualNetworkRule -ResourceGroupName joynet -ServerName joyser -VirtualNetworkRuleName vnetrule1 -VirtualNetworkSubnetId $virtualNetworkSubnetId
要解决此问题,请尝试使用Clear-AzContext
清除所有本地帐户信息,然后使用以下脚本重新登录。
$azureAplicationId ="<Application ID>"
$azureTenantId= "<Tenant ID>"
$azurePassword = ConvertTo-SecureString "<Client secret>" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
然后运行(Get-AzContext).Account
,确保与您正在使用的服务主体的Id
相同,服务主体的也应与中的 GUID 相同。Application ID
Tenant ID
Tenants
推荐阅读
- java - 排序方法未正确排序
- java - Java 2d 游戏:为什么变量在 KeyReleased 之外没有改变?
- python - 函数'where'如何生成这个数组?
- java - collections.sort 不排序,仅获取未排序的输出
- c# - 如果视图组件只进行异步调用,我是否需要对 Razor 页面 OnGet ActionResult 进行异步操作
- python - 使用 dask 在两个大熊猫数据框之间进行内部连接
- react-native - 如何使用状态栏正确显示本机顶部选项卡和堆栈导航器?
- mysql - mysql查询返回两个单独的数组
- jsf - 我将如何实现非托管 bean 和 JSF 组件之间的交互?
- sql - 在 SQL 中使用 CASE 正确计算带有 if/else 逻辑的项目