简体   繁体   English

Microsoft.Practices.EnterpriseLibrary.Data.dll中发生了类型为'System.InvalidOperationException'的异常

[英]An exception of type 'System.InvalidOperationException' occurred in Microsoft.Practices.EnterpriseLibrary.Data.dll

I am facing this error: An exception of type 'System.InvalidOperationException' occurred in Microsoft.Practices.EnterpriseLibrary.Data.dll but was not handled in user code .Additional information: The number of parameters does not match number of values for stored procedure. 我遇到此错误:Microsoft.Practices.EnterpriseLibrary.Data.dll中发生了类型为'System.InvalidOperationException'的异常,但未在用户代码中处理。其他信息:参数数量与存储过程的值数量不匹配。 Here is my code: 这是我的代码:

public static IEnumerable<abcProduct> GetAll()
{
    string cnn =
    "database connectionstring";
    using (OracleConnection conn = new OracleConnection(cnn))
    {
        conn.Open();
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandText = "package_name.sp_name";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("resultset_out", OracleDbType.RefCursor, ParameterDirection.Output);
        OracleDataReader rdr = cmd.ExecuteReader();
        //rdr.Read();
        while (rdr.Read())
        {
            yield return new vProduct(GetNullableValue<string>(rdr["ABC_PRODUCT"]), GetNullableValue<string>(rdr["ABC_PRODUCT_AREA"]));
        }
    }
}

Here is my store procedure structure 这是我的存储过程结构

PROCEDURE PRC_ABC_PRODUCTS_GETALL(resultset_out OUTPUT TYPES.cursorType) AS

BEGIN
    OPEN resultset_out
    FOR

    SELECT UPPER(products.abc_product) abc_product,
        MAX(productareas.abc_product_area) abc_product_area
    FROM SCHEMA.AS_ABC_PRODUCT products
    LEFT JOIN SCHEMA.AS_ABC_PRODUCT_AREA productareas
        ON products.V_PRODUCT_AREA_ID = productareas.ABC_PRODUCT_AREA_ID
    WHERE products.VALID = 1
        AND products.abc_product NOT LIKE '$%'
    GROUP BY UPPER(products.abc_product),
        UPPER(productareas.abc_product_area)
    ORDER BY UPPER(products.ABC_PRODUCT);
END

PRC_ABC_PRODUCTS_GETALL;

Can anyone help on this? 有人可以帮忙吗? Can anybody point out what is the error?A little help would be greatly appreciated :-) 有人能指出错误是什么吗?一点帮助将不胜感激:-)

I see several issues in your code. 我在您的代码中看到了几个问题。

  • It should be cmd.CommandText = "PRC_ABC_PRODUCTS_GETALL"; 应该是cmd.CommandText = "PRC_ABC_PRODUCTS_GETALL"; instead of cmd.CommandText = "package_name.sp_name"; 而不是cmd.CommandText = "package_name.sp_name";

  • resultset_out OUTPUT TYPES.cursorType is not valid Oracle Syntax. resultset_out OUTPUT TYPES.cursorType是无效的Oracle语法。 Should be resultset_out OUT SYS_REFCURSOR . 应该是resultset_out OUT SYS_REFCURSOR Were you able to compile the procedure? 您能够编译该程序吗?

Try it like this: 像这样尝试:

cmd.CommandText = "begin res := PRC_ABC_PRODUCTS_GETALL; end;";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("res", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
OracleDataReader rdr = cmd.ExecuteReader();

and this PL/SQL: 和这个PL / SQL:

FUNCTION PRC_ABC_PRODUCTS_GETALL RETURN SYS_REFCURSOR AS
   resultset_out SYS_REFCURSOR;
BEGIN
    OPEN resultset_out
    FOR

    SELECT UPPER(products.abc_product) abc_product,
        MAX(productareas.abc_product_area) abc_product_area
    FROM SCHEMA.AS_ABC_PRODUCT products
    LEFT JOIN SCHEMA.AS_ABC_PRODUCT_AREA productareas
        ON products.V_PRODUCT_AREA_ID = productareas.ABC_PRODUCT_AREA_ID
    WHERE products.VALID = 1
        AND products.abc_product NOT LIKE '$%'
    GROUP BY UPPER(products.abc_product),
        UPPER(productareas.abc_product_area)
    ORDER BY UPPER(products.ABC_PRODUCT);

    RETURN resultset_out;
END;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.dll中发生了类型为&#39;System.InvalidOperationException&#39;的未处理异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll 发生未处理的异常C#的system.data.dll中发生了类型&#39;system.invalidoperationexception&#39;的未处理异常 - An unhandled exception occured an unhandled exception of type 'system.invalidoperationexception' occurred in system.data.dll in c# WebDriver.dll中发生了未处理的“System.InvalidOperationException”类型异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll mscorlib.dll中发生了类型为&#39;System.InvalidOperationException&#39;的未处理异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll 将数据插入Gridview的System.Data.dll中发生类型为&#39;System.InvalidOperationException&#39;的异常 - An exception of type 'System.InvalidOperationException' occurred in System.Data.dll that inserting data into Gridview System.Data.dll 中发生类型为“System.InvalidOperationException”的第一次机会异常 - A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll ExecuteReader- System.Data.dll中发生类型为“System.InvalidOperationException”的异常,但未在用户代码中处理 - ExecuteReader- An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code System.Data.dll (SqlTransaction) 中出现“System.InvalidOperationException”类型的未处理异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll (SqlTransaction) System.Data.dll中发生类型为&#39;System.InvalidOperationException&#39;的未处理异常-C#Visual Studio - An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll - C# visual studio System.Data.dll 430中发生类型为&#39;System.InvalidOperationException&#39;的未处理异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll 430
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM