我有一个方法,我想执行存储过程并从中获取状态和响应。执行 my 时cmd.ExecuteNonQuery()
,出现错误:
由于对象的当前状态,操作无效
这是代码:
public static string GET_IPL_STATUS_ON_NEID(string NEID)
{
string strStatus = string.Empty; string strMessage = string.Empty;
OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionStringAppAuto"].ConnectionString);
try
{
OracleCommand cmd = new OracleCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = ConfigurationManager.AppSettings["GET_IP_STATUS_PROC"].ToString();
cmd.Parameters.Add(new OracleParameter { ParameterName = "P_A6_NEID", Value = NEID, OracleDbType = OracleDbType.Varchar2, Direction = ParameterDirection.Input });
cmd.Parameters.Add(new OracleParameter
{
ParameterName = "STATUS",
OracleDbType = OracleDbType.Varchar2,
Size = 500,
Direction = ParameterDirection.Output
});
cmd.Parameters.Add(new OracleParameter
{
ParameterName = "MESSAGE",
OracleDbType = OracleDbType.Varchar2,
Size = 500,
Direction = ParameterDirection.Output
});
if (conn.State != ConnectionState.Open) conn.Open();
cmd.ExecuteNonQuery();
strStatus = cmd.Parameters["STATUS"].Value.ToString();
strMessage = cmd.Parameters["MESSAGE"].Value.ToString();
}
catch (Exception ex)
{
throw;
}
finally
{
if (conn.State == ConnectionState.Open) conn.Close();
}
return strStatus;
}
根据文档中的示例
OracleCommand
,您需要Connection
在命令上设置属性以告诉它使用哪个连接: