Hi I am detaching few databases from a sql instance from powershell, then we have a process that does a clone of the disks from another instance and restarts sql service. Then another process attaches all the databases(using invoke-sqlcmd) detached earlier
and executes a stored proc. But when am executing the stored proc , i get this error..
Exception calling "Fill" with "1" argument(s): "A transport-level error has occurred when sending the request to the server. (provider:Shared Memory Provider, error: 0 - The pipe is being closed.)"
Code below to execute the sql commands. But i don't get this error when i run the command again , any way to clear the pool?
Thanks
$lclSqlConn = New-Object System.Data.SqlClient.SqlConnection
$lclSqlConn.ConnectionString = "$ConnStr"
$lclSqlConn.Open() | out-null
$lclSqlCmd = New-Object System.Data.SqlClient.SqlCommand
$lclSqlCmd.Connection = $lclSqlConn
$lclSqlCmd.CommandText = $Cmd
$lclSqlCmd.CommandTimeout=$QueryTimeout
if ( $CmdType.ToUpper() -eq "SP") {
$lclSqlCmd.CommandType = [System.Data.CommandType]'StoredProcedure'
} else {
$lclSqlCmd.CommandType = [System.Data.CommandType]'Text'
}
if (($CmdParam) -and ($CmdType -eq "SP")) {
$CmdParam.split($Sep1) | Foreach-Object {
$pos = $_.IndexOf($Sep2)
$lclPar = @($_.Substring(0, $pos),$_.Substring($pos+$Sep2.length))
$lclSqlCmd.Parameters.AddWithValue($lclPar[0],$lclPar[1]) | out-Null
}
}
$lclSqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$lclSqlAdapter.SelectCommand = $lclSqlCmd
$lclDataSet = New-Object System.Data.DataSet
$lclSqlAdapter.Fill($lclDataSet) | Out-Null
$lclSqlConn.Close()
return @{"ExitCode" = $true; "ExitMsg" = ""; "DataSet" = $lclDataSet; "ErrorType" = $null; "SQLErrNr" = $null; "SQLState" = $null}
}
catch [System.Data.SqlClient.SqlException] {
return @{"ExitCode" = $false; "ExitMsg" = $error[0].ToString(); "DataSet" = $null; "ErrorType" = "SQL"; "SQLErrNr" = $_.Exception.GetBaseException().Number; "SQLState"
= $_.Exception.GetBaseException().State}
}
catch {
return @{"ExitCode" = $false; "ExitMsg" = $error[0].ToString(); "DataSet" = $null; "ErrorType" = "APP"; "SQLErrNr" = $null; "SQLState" = $null}
}