Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to close open cursors?

519887Sep 7 2007 — edited Sep 11 2007
Hello,

I've a simple stored procedure:
----------------------------------------------------------------------------------
create or replace procedure Test(rs out sys_refcursor) as
begin
open rs for
select 1 from dual;
end;
----------------------------------------------------------------------------------

I wrote a simple .NET application and executed the stored procedure. I disposed Command object, I closed & disposed Connection object, but still the cursor stays there. When I close the application, then only the cursor goes away...Any idea how to close/distroy cursor?

I'm using ODP.NET, n my .NET code looks like this-
---------------------------------------------------------------------------------
OracleCommand cmd = new OracleCommand();
cmd.Parameters.Add("RS", OracleDbType.RefCursor, ParameterDirection.Output);
OracleConnection conn = new OracleConnection();
conn.ConnectionString = ""XXXXXXXX";
cmd.Connection = conn;
cmd.CommandText = "Test";
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();

cmd.ExecuteScalar();

cmd.Dispose();
conn.Close();
conn.Dispose();
---------------------------------------------------------------------------------

I use following SQL command to check open cursors-
---------------------------------------------------------------------------------
SELECT v.value as numopencursors ,s.machine ,s.osuser,s.username, s.PROGRAM
FROM V$SESSTAT v, V$SESSION s
WHERE v.statistic# = 3 and v.sid = s.sid and username='XXXXXXXXX'
---------------------------------------------------------------------------------

Thanks,
Amit M
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 9 2007
Added on Sep 7 2007
6 comments
2,184 views