简体   繁体   English

使用“2”参数调用“.ctor”的异常:“数据库'XXX'的SetParent失败。”

[英]Exception calling “.ctor” with “2” argument(s): “SetParent failed for Database 'XXX' .”

I have a problem with running SQLPS commands to create a DB on Windows Server 2012R2 and Powershell v4 我在运行SQLPS命令以在Windows Server 2012R2和Powershell v4上创建数据库时遇到问题

#Import SQL Server Module called SQLPS
Import-Module SQLPS -DisableNameChecking

#Your SQL Server Instance Name
$Inst = "sql03"
$Srvr = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $Inst

#database PSDB with default settings
#by assuming that this database does not yet exist in current instance
$DBName = "PSDB"
$db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database($Srvr, $DBName)
$db.Create()

#Confirm, list databases in your current instance
$Srvr.Databases |
Select Name, Status, Owner, CreateDate

I receive the below error: 我收到以下错误:

New-Object : Exception calling ".ctor" with "2" argument(s): "SetParent failed for Database 'PSDB'. "
At C:\test.ps1:11 char:7
+ $db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database($Srvr, $D ...
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\test.ps1:12 char:1
+ $db.Create()
+ ~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The following exception occurred while trying to enumerate the collection: "Failed to connect to server sql03.".
At C:\test.ps1:15 char:1
+ $Srvr.Databases |
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : ExceptionInGetEnumerator

Any suggestions how to fix this? 有任何建议如何解决这个问题?

If you are working locally try replacing: 如果您在本地工作,请尝试更换:

$Srvr = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $Inst

With: 附:

$Srvr = new-object ('Microsoft.SqlServer.Management.Smo.Server') localhost

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用“2”参数调用“.ctor”的异常:“SetParent 登录 'XXX' 失败。” - Exception calling “.ctor” with “2” argument(s): “SetParent failed for Login 'XXX'.” 使用“0”参数调用“ExecuteNonQuery”时发生异常 - Exception calling "ExecuteNonQuery" with "0" argument(s) 异常调用参数为“ 0”的“ ExecuteNonQuery”:“参数化查询 - Exception calling “ExecuteNonQuery” with “0” argument(s): "The parameterized query 使用Powershell部署数据库dacpac:使用“ 3”参数调用“ Deploy”的异常:“无法部署程序包。” - Deploy Database dacpac with Powershell: Exception calling “Deploy” with “3” argument(s): “Could not deploy package.” SETPARENT失败,用于FULLTEXTINDEXCOLUMN - SETPARENT FAILED FOR FULLTEXTINDEXCOLUMN Power Shell Invoke-SQLSelect:使用“1”参数调用“Fill”的异常: - Power Shell Invoke-SQLSelect : Exception calling "Fill" with "1" argument(s): 使用“ 0”参数调用“ ExecuteReader”的异常:“'='附近的语法不正确。” - Exception calling “ExecuteReader” with “0” argument(s): “Incorrect syntax near '='.” 数据库SQL Server 2012的setparent失败 - setparent fail for database sql server 2012 数据库的PowerShell登录失败,但没有异常 - PowerShell login failed for database but no exception 用户“ sa”的SQL Server登录失败。 [CLINET:XXX:XXX:XXX:XXX] - Sql Server Login failed for user 'sa'. [CLINET: XXX:XXX:XXX:XXX]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM