title: Exception calling ".ctor" with "2" argument(s): "SetParent failed for Database 'XXX' ."
body: <p>I have a problem with running SQLPS commands to create a DB on Windows Server 2012R2 and Powershell v4</p>
  
  <pre><code>#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
  </code></pre>
  
  <p>I receive the below error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Any suggestions how to fix this?</p>