简体   繁体   English

C#OleDB-Oracle存储过程不返回数据

[英]C# OleDB - Oracle Stored Procedure not returning data

I have the following C# code that is calling a stored procedure, but no data is being returned (empty/null dataset.) If I run the stored proc in TOAD, I definitely get results (one row.) I can change the command text to "SELECT * FROM DUAL" and I get data returned, so I know the database is making a successful connection. 我有以下C#代码正在调用存储过程,但是没有返回任何数据(空/空数据集。)如果在TOAD中运行存储的proc,我肯定会得到结果(一行)。我可以更改命令文本到“ SELECT * FROM DUAL”,我得到返回的数据,所以我知道数据库正在成功建立连接。 The stored proc takes one input parameter, and outputs five fields. 存储的过程采用一个输入参数,并输出五个字段。 Here's my code: 这是我的代码:

        string connStr = "Provider=OraOLEDB.Oracle;Data Source=database;User Id=username;Password=password;PLSQLRSet=1;";
        OleDbConnection oracleConn = new OleDbConnection(connStr);

        OleDbCommand cmd = new OleDbCommand("{call foo.bar(?, ?, ?, ?, ?, ?)}", oracleConn);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.Add("p_login", OleDbType.VarChar, 50);
        cmd.Parameters["p_login"].Direction = ParameterDirection.Input;
        cmd.Parameters["p_login"].Value= "FOOBAR";
        cmd.Parameters.Add("p_user_id", OleDbType.VarChar, 50);
        cmd.Parameters["p_user_id"].Direction = ParameterDirection.Output;
        cmd.Parameters.Add("p_user_role", OleDbType.VarChar, 50);
        cmd.Parameters["p_user_role"].Direction = ParameterDirection.Output;
        cmd.Parameters.Add("p_user_first_name", OleDbType.VarChar, 50);
        cmd.Parameters["p_user_first_name"].Direction = ParameterDirection.Output;
        cmd.Parameters.Add("p_user_last_name", OleDbType.VarChar, 50);
        cmd.Parameters["p_user_last_name"].Direction = ParameterDirection.Output;
        cmd.Parameters.Add("p_user_terr_nbr", OleDbType.VarChar, 50);
        cmd.Parameters["p_user_terr_nbr"].Direction = ParameterDirection.Output;
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "dsTest");
        return ds;

I'd recommend inserting logging into stored procedure and seeing what kinds of data are sent to Oracle instance or if the procedure is called at all. 我建议将日志记录插入存储过程,并查看将哪些类型的数据发送到Oracle实例,或者是否完全调用了该过程。 And then debugging from there. 然后从那里调试。

As of general, there may be some disconnection between data types you're sending or input/output parameters. 通常,您正在发送的数据类型或输入/输出参数之间可能会断开连接。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM