我有一个用于调用 SP 的 powershell 脚本,如下所示
$sqlTableConnection = New-Object [System.Data.SqlClient.SqlConnection]("Server=1xx.xx.xxx; Database=dbName; Integrated Security= True");
$sqlTableCmd = New-Object [System.Data.SqlClient.SqlCommand]
$sqlTableCmd.CommandText = "[System_Control].[usp_Check_system]"
$sqlTableCmd.Connection = $sqlTableConnection;
$jobName1 = "MASTER_JOB";
$sqlTableCmd.Parameters.AddWithValue("@JobName", $jobName1) ;
$outParameter = new-object System.Data.SqlClient.SqlParameter;
$outParameter.ParameterName = "@JobSatatus";
$outParameter.Direction = [System.Data.ParameterDirection]'Output';
$outParameter.DbType = [System.Data.DbType]'Boolean';
$sqlTableCmd.Parameters.Add($outParameter) ;
$sqlTableCmd.Connection = $sqlTableConnection
$sqlTableConnection.Open();
$sqlTableCmd.ExecuteNonQuery();
$truth = $sqlTableCmd.Parameters["@JobSatatus"].Value;
$sqlTableConnection.Close();
$truth;
但是当我运行它时,我遇到了错误
Exception calling "ExecuteNonQuery" with "0" argument(s): "The variable name '@
JobName' has already been declared. Variable names must be unique within a quer
y batch or stored procedure."
At line:15 char:33
+ $sqlTableCmd.ExecuteNonQuery <<<< ();
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
我在哪里做错了?