How to close open cursors?
519887Sep 7 2007 — edited Sep 11 2007Hello,
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