当我第一次尝试运行以下代码时,我得到一个无法解释的错误,但在第二次尝试时再次运行脚本工作正常......我的代码有什么问题?
顺便说一句,我在这一步之前创建数据库......
$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()
错误
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 <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException