gpt4 book ai didi

powershell - 创建 Azure SQL 数据库服务器连接上下文 New-AzureSqlDatabaseServerContext

转载 作者:行者123 更新时间:2023-12-03 00:15:42 24 4
gpt4 key购买 nike

我正在尝试创建一个 Azure SQL 数据库连接上下文,例如

$cred = Get-Credential
$ctx = New-AzureSqlDatabaseServerContext -ServerName “mydatabasename” -credential $cred

$pwd = ConvertTo-SecureString "[password1234]" -AsPlainText -Force;
$cred1 = New-Object System.Management.Automation.PSCredential -ArgumentList "databaseadmin", $pwd
New-AzureSqlDatabaseServerContext -ServerName "myservername" -Credential $cred1

响应是:

New-AzureSqlDatabaseServerContext : Object reference not set to an instance of an object.
At line:2 char:8
+ $ctx = New-AzureSqlDatabaseServerContext -ServerName “myservername” - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureSqlDatabaseServerContext], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.SqlDatabase.Database.Cmdlet.NewAzureSqlDatabaseServerContext

我已经浏览了文档和谷歌搜索,但没有结果。 https://msdn.microsoft.com/en-us/library/dn546736.aspx http://sqlmag.com/powershell/manage-azure-sql-databases-powershell

谢谢帕维尔

最佳答案

我最近在 PS Runbook 中遇到了这个问题。经过一番搜索后,我找到了一个适合我的解决方案。希望对您有帮助。

该错误消息并不是特别有帮助(大惊喜),但引用的空对象是 Azure 订阅;我假设异常是从 cmdlet 内部冒出的,而不是由您自己的代码抛出的。通过将这三行添加到我的代码中:

$cert = Get-AutomationCertificate -Name $automationCertificateName;
Set-AzureSubscription -SubscriptionName $subName -Certificate $cert -SubscriptionId $subID;
Select-AzureSubscription -Current $subName;

我能够克服异常。上面的 $automationCertificateName 是我添加到自动化帐户的可变 Assets 。请参阅https://github.com/Microsoft/sql-server-samples/tree/master/samples/manage/azure-automation-automated-export有关如何设置的详细信息。

关于powershell - 创建 Azure SQL 数据库服务器连接上下文 New-AzureSqlDatabaseServerContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34890243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com