I haven't been able to find this explicitly stated anywhere yet, but a bunch of examples I've found online follow what I've been doing.
I have a C# class which uses ODP.net to connect to an Oracle DB and run a procedure that's in a package.
My package has stored procedures which take a ref cursor output parameter. All the procedure does is open up the cursor for a particular select statement.
If I execute this procedure directly on the oracle db, then eventually I'll hit a max number of open cursors error.
So I was wondering if ODP.net does indeed close this cursor that was opened in my procedure?
I'm using the OracleDataApaper.Fill(DataSet) method.
eg.
DataSet ds = new DataSet();
OracleConnection conn = new OracleConnection(this.connStr);
OracleCommand com = new OracleCommand("MYPKG.MYQUERY", conn);
OracleDataAdapter adapter = new OracleDataAdapter(com);
conn.Open();
com.Parameters.Add("searchParam", OracleDbType.Varchar2).Value = "myName";
com.Parameters.Add("outCursor", OracleDbType.RefCursor, ParameterDirection.Output);
com.CommandType = CommandType.StoredProcedure;
adapter.Fill(ds);
conn.Close();
PROCEDURE GETALLEMAILS(searchParamIN VARCHAR2, outCursor OUT sys_refcursor) AS
BEGIN
open outCursor
select
EAEMAL as Email
from
EmailTable
where
EmailName = searchParam;
END GETALLEMAILS;
I'm just afraid of leaving open cursors behind on the DB is all. If anyone can provide links to official documentation, that'd be great!
Updates:
Thanks for the input. I was calling
com.Dispose();
conn.Close();
conn.Dispose();
but left them out of my example.
I found this forum post, which states that the OracleDataAdapter.Fill(Dataset) method does release the ref cursor after the Fill() method has been executed.
http://www.frontoracle.com/oracle-archive/140/386140-close-ref-cursor.html
I wish the Oracle documentation was more explicit in describing this process though.