Maximum Cursors Exceeded

Most often GIS developer may come across the error ‘ORA-01000: maximum open cursors exceeded ‘. Why is this happens?, how to solve. Generally, this error will occur while looping through the featureclass. Whenever we loop through featureclass or table, we need to release cursor object after using it.

Here is simple VB.NET function to release cursor object.


Public Sub MarshalObject(ByRef obj As Object)

If Not obj Is Nothing Then
 If System.Runtime.InteropServices.Marshal.IsComObject(obj) Then
   End If
           obj = Nothing
   End If
 End Sub

C#.NET sample

private static void MarshalCOMObject(object obj)


if (obj != null)


if (System.Runtime.InteropServices.Marshal.IsComObject(obj))



obj = null;



} You can call this subroutine at appropriate place. Here important point, you need to release both ‘ROW’ object and ‘CURSOR’ object after usage.  The pseudo code to understand the concept using C#.NE



//Assuming variables are declared pQueryFilter = new QueryFilterClass();

pQueryFilter.WhereClause = “”;

pCursor = pFeatureClass.Search(pQueryFilter, false);

pFeature = pCursor.NextFeature();

while (pFeat != null) 


//Do whaterver required

//Release feature row object using MarshalCOMObject subroutine.


pFeature = pCursor.NextFeature();


//After looping is finised release cursor object using MarshalCOMObject subroutine.



catch (Exception ex)

{ }


{ //In case any error occured within try block, finally block  releases cursor and

//row object using MarshalCOMObject subroutine.




I hope this sample helps you in concept on releasing the cursor objects


3 Responses to “Maximum Cursors Exceeded”

  1. Coding Practices and list of Frequent Errors « Says:

    […] You can get sample code and detail on clicking this. […]

  2. Srinivasan Says:

    Hi Lakshman,

    Very nice tip for releasing cursor….Thanks..

  3. Alvaro Montero Says:

    Great! this really help me. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: