从Web Service调用存储过程时无法删除记录

时间:2014-03-06 20:44:23

标签: c# .net oracle stored-procedures package

我在包中有以下存储过程:

PROCEDURE DELETE_RECORD(serial IN NUMBER, code IN NUMBER, brand IN VARCHAR2, response OUT VARCHAR2) IS
BEGIN
    DELETE FROM CWPESME.cwpesme_campaign_subsc
    WHERE 
    sku = serial
    AND id = code
    AND mfg = brand;
    COMMIT;
        response := 'SUCCESS';
    EXCEPTION WHEN OTHERS THEN
        response := 'FAILURE '||SQLERRM;
END DELETE_RECORD;

这就是我从网络服务中调用它的方式:

[WebMethod]
public string del_record(int serial, int code, string brand)
{
    using (OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["cs"].ConnectionString))
    {
        using (OracleCommand cmd = conn.CreateCommand())
        {
            cmd.CommandText = "MyPackage.DELETE_RECORD";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add("sku", OracleType.Number, 38).Direction = System.Data.ParameterDirection.Input;
            cmd.Parameters["sku"].Value = serial;
            cmd.Parameters.Add("id", OracleType.Number, 38).Direction = System.Data.ParameterDirection.Input;
            cmd.Parameters["id"].Value = code;
            cmd.Parameters.Add("mfg", OracleType.VarChar, 250).Direction = System.Data.ParameterDirection.Input;
            cmd.Parameters["mfg"].Value = brand;
            cmd.Parameters.Add("response", OracleType.VarChar, 550).Direction = System.Data.ParameterDirection.Output;

            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                string result = cmd.Parameters["response"].Value.ToString();
                return result;
            }
            catch (Exception ex)
            {
                string result = cmd.Parameters["response"].Value.ToString();
                return (result != string.Empty) ? result : "[FAILURE] " + ex.ToString();
            }
        }
    }
}

如果直接调用存储过程,我可以删除记录,但在从Web服务调用时无法删除。不过,我可以SELECTUPDATE这样做。发生了什么事?

1 个答案:

答案 0 :(得分:0)

代码没有错;重新检查用户并授予该表的所有权限,现在可以删除行。