# How to call oracle stored procedure with output in code behind

**URL:** <https://discuss.workflowgen.com/t/how-to-call-oracle-stored-procedure-with-output-in-code-behind/1958>\
**Category:** Development\
**Created:** [October 13, 2021, 8:39am UTC](https://discuss.workflowgen.com/t/how-to-call-oracle-stored-procedure-with-output-in-code-behind/1958 "2021-10-13T08:39:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wing\_hou](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@wing\_hou](https://discuss.workflowgen.com/u/wing_hou)\
**Post date:** [October 13, 2021, 8:39am UTC](https://discuss.workflowgen.com/t/how-to-call-oracle-stored-procedure-with-output-in-code-behind/1958/1 "2021-10-13T08:39:23Z")

</div>

I tried to use the code below to call stored procedure but failed.

```auto
using (Oracle.ManagedDataAccess.Client.OracleConnection conn = new Oracle.ManagedDataAccess.Client.OracleConnection(connectionString))
	        {	            
	            Oracle.ManagedDataAccess.Client.OracleCommand cmd = new Oracle.ManagedDataAccess.Client.OracleCommand();
	            cmd.Connection = conn;
	            cmd.CommandText = "xxtmtm_s0005.UPDATE_EBS_ITEM_STATUS";
	            cmd.CommandType = CommandType.StoredProcedure;
	            cmd.Parameters.Add("PRA_ITEM",OracleType.VarChar).Value = "6LH60083100";
	            cmd.Parameters.Add("PRA_NEW_STATUS",OracleType.VarChar).Value = "FAP_SS Y";
	            cmd.Parameters.Add("PRA_EMP_NO",OracleType.VarChar).Value = "EBSSUPP2";
	            cmd.Parameters.Add("PRA_RESULT",OracleType.VarChar).Direction = ParameterDirection.Output;
	            
	            conn.Open();
	            cmd.ExecuteNonQuery();
	            Oracle.ManagedDataAccess.Client.OracleDataReader rdr = cmd.ExecuteReader();
	            
	            if(rdr.HasRows)
	            {
	                while(rdr.Read())
	                {
	                    test = rdr["PRA_RESULT"].ToString();
	                }
	            }
	            
	            conn.Close();
	            conn.Dispose();
	        }

```

The error is shown as below:

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/workflowgen/original/1X/1181f6b3b118ec5b70da94520358b72087026c86.png)

Is there any other method to call oracle stored procedure with code behind?

---

<div class="post-metadata">

**Author:** ![eddy.daouk](https://yyz2.discourse-cdn.com/flex030/user_avatar/discuss.workflowgen.com/eddy.daouk/32/672_2.png) [@eddy.daouk](https://discuss.workflowgen.com/u/eddy.daouk)\
**Post date:** [October 14, 2021, 2:49pm UTC](https://discuss.workflowgen.com/t/how-to-call-oracle-stored-procedure-with-output-in-code-behind/1958/2 "2021-10-14T14:49:24Z")

</div>

Hi @wing_hou,

For this code to work, you’ll need to put the assembly (.dll file) used for “Oracle.ManagedDataAccess” in `wfgen/wfapps/webforms/bin` folder located in your application server.

The code behind editor will try to look for assemblies in this folder.

Regards,  
Eddy.

---

<div class="post-metadata">

**Author:** ![wing\_hou](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@wing\_hou](https://discuss.workflowgen.com/u/wing_hou)\
**Post date:** [October 15, 2021, 1:46am UTC](https://discuss.workflowgen.com/t/how-to-call-oracle-stored-procedure-with-output-in-code-behind/1958/3 "2021-10-15T01:46:29Z")

</div>

Hi @eddy.daouk ,

I have checked that “Oracle.ManagedDataAccess.dll” had already exist in the wfgen/wfapps/webforms/bin folder.  
Is there any other assembly file that I need to put into that folder?

I found out that if I change the code like below, the script can found the context:

```auto
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("PRA_RESULT",OracleType.VarChar).Direction = System.Data.ParameterDirection.Output;

```

But I have no idea what namespace should be put for the ‘OracleType’

```auto
cmd.Parameters.Add("PRA_ITEM", **OracleType.VarChar** ).Value = "6LH60083100";

```

---

<div class="post-metadata">

**Author:** ![kevin.lee](https://avatars.discourse-cdn.com/v4/letter/k/65b543/32.png) [@kevin.lee](https://discuss.workflowgen.com/u/kevin.lee)\
**Post date:** [October 16, 2021, 1:33am UTC](https://discuss.workflowgen.com/t/how-to-call-oracle-stored-procedure-with-output-in-code-behind/1958/4 "2021-10-16T01:33:03Z")

</div>

Should you not use OracleDbType which is part of the Oracle.DataAccess.Client namespace?

[https://docs.oracle.com/database/121/ODPNT/OracleParameterClass.htm#ODPNT1771](https://docs.oracle.com/database/121/ODPNT/OracleParameterClass.htm#ODPNT1771)

[https://docs.oracle.com/cd/B19306\_01/win.102/b14307/OracleDbTypeEnumerationType.htm](https://docs.oracle.com/cd/B19306_01/win.102/b14307/OracleDbTypeEnumerationType.htm)

---

<div class="post-metadata">

**Author:** ![wing\_hou](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@wing\_hou](https://discuss.workflowgen.com/u/wing_hou)\
**Post date:** [October 18, 2021, 12:04am UTC](https://discuss.workflowgen.com/t/how-to-call-oracle-stored-procedure-with-output-in-code-behind/1958/5 "2021-10-18T00:04:42Z")

</div>

Hi, @kevin.lee

Thanks for your help.

After changing the code as below, it works.

```auto
using (Oracle.ManagedDataAccess.Client.OracleConnection conn2 = new Oracle.ManagedDataAccess.Client.OracleConnection(connectionString2))
{
	            Oracle.ManagedDataAccess.Client.OracleCommand cmd2 = new Oracle.ManagedDataAccess.Client.OracleCommand();
	            cmd2.Connection = conn2;
	            cmd2.CommandText = "XXTMTM_S0005.UPDATE_EBS_ITEM_STATUS";
	            cmd2.CommandType = System.Data.CommandType.StoredProcedure;
	            cmd2.Parameters.Add("PRA_ITEM_CODE", Oracle.ManagedDataAccess.Client.OracleDbType.Varchar2,System.Data.ParameterDirection.Input).Value = "6LH60083100";
	            cmd2.Parameters.Add("PRA_NEW_STATUS", Oracle.ManagedDataAccess.Client.OracleDbType.Varchar2,System.Data.ParameterDirection.Input).Value = "FAP_SS Y";
	            cmd2.Parameters.Add("PRA_EMP_NO", Oracle.ManagedDataAccess.Client.OracleDbType.Varchar2,System.Data.ParameterDirection.Input).Value = "EBSSUPP2";
	            cmd2.Parameters.Add("PRA_RESULT", Oracle.ManagedDataAccess.Client.OracleDbType.Varchar2,System.Data.ParameterDirection.Output).Size = 10;
	            
	            conn2.Open();
	            cmd2.ExecuteNonQuery();
	            output = ["PRA_RESULT"].Value;

	            conn2.Close();
	            conn2.Dispose();
}

```
