title: Sql Command (Exception calling "ExecuteScalar" with "0" argument)
body: <p>When I run the below code on first attempt I get an unexplained error, but running the script again on a second attempt works fine...what would be wrong in my code?</p>
  
  <p>By the way I am creating the database before this step...</p>
  
  <pre><code>  $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $SqlConnection.ConnectionString = "Server=$dBServer;Database=$dBName;Integrated Security=True" 
    $SqlConnection.Open() 
  
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand 
    $SqlCmd.CommandText = $dBCmd 
    $SqlCmd.Connection = $sqlConnection 
  
    $execute = $SqlCmd.ExecuteScalar() 
    $SqlConnection.Close() 
  </code></pre>
  
  <p>Error </p>
  
  <pre><code>Exception calling "ExecuteScalar" with "0" argument(s): "A transport-level error has occurred when sending the request to the server. (provider: Shared Memory  Provider, error: 0 - No process is on the other end of the pipe.)" At c:\scripts\DB\Powershell\RunSql.ps1:61 char:34
  +   $execute = $sqlCmd.ExecuteScalar &lt;&lt;&lt;&lt; ()
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : DotNetMethodException
  </code></pre>