ORA-01000: maximum open cursors exceeded

4186
4
07-19-2011 07:08 AM
CarlosPiccirillo
New Contributor III
Hi everyone,

I have a standalone C# application that contains the following procedure which gets called to find a particular feature within an array of layers. This procedure gets called numerous times from inside a loop. Everything works fine for the first 25 passes but on the 26th pass, I get an error of "ORA-01000: maximum open cursors exceeded" on line pFeatureClass = pFeatureWorkspace.OpenFeatureClass(permitType).

No matter where I try to do marshall release to free up the com objects, I keep getting the error. Been fighting with this for almost a day now and I'm out of ideas.

Any insights are GREATLY appreciated!
Carlos


        internal static void FindApplication(string appNo, out IFeature pOutFeature, out IFeatureClass pOutFeatureClass)
        {
            IPropertySet pPropertySet = new PropertySetClass();
            IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkspace = null;
            IFeatureClass pFeatureClass = null;
            IQueryFilter pQueryFilter = new QueryFilterClass();
            IFeatureCursor pFeatureCursor = null;
            IFeature pFeature = null;
            pOutFeature = null;
            pOutFeatureClass = null;
            string permitType = string.Empty;

            try
            {
                pPropertySet.SetProperty("Server", "gerrdsde");
                pPropertySet.SetProperty("Instance", "5154");
                pPropertySet.SetProperty("Database", "gerrd");
                pPropertySet.SetProperty("User", "rim");
                pPropertySet.SetProperty("Password", "RPS4240sde");
                pPropertySet.SetProperty("Version", "SDE.DEFAULT");

                string[] layerArray = {"RIM.PRSTF_JDS_APP_AREA", "RIM.PRSTF_SBL_APP_AREA", "RIM.PRSTF_OST_APP_AREA",
                                       "RIM.PRSTF_DAF_APP_AREA", "RIM.PRSTF_AQU_APP_AREA", "RIM.PRSTF_WDI_APP_AREA",
                                       "RIM.PRSTF_MIT_APP_AREA", "RIM.PRSTF_WDF_APP_AREA", "RIM.PRSTF_WUP_PWS_APP_AREA",
                                       "RIM.PRSTF_WUP_DEW_APP_AREA", "RIM.PRSTF_WUP_DIV_APP_AREA", "RIM.PRSTF_WUP_APP_AREA",
                                       "RIM.PRSTF_SWM_APP_AREA", "RIM.PRSTF_ERP_APP_AREA", "RIM.PRSTF_LOK_APP_AREA",
                                       "RIM.PRSTF_WQE_AREA"};

                for (int i = 0; i < layerArray.Length; i++)
                {
                    permitType = layerArray;
                    IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
                    pFeatureWorkspace = pWorkspaceFactory.Open(pPropertySet, 0) as IFeatureWorkspace;
                    pFeatureClass = pFeatureWorkspace.OpenFeatureClass(permitType);

                    pQueryFilter = new QueryFilter();
                    pQueryFilter.WhereClause = "APP_NO = '" + appNo + "'";

                    pFeatureCursor = pFeatureClass.Search(pQueryFilter, false);
                    pFeature = pFeatureCursor.NextFeature();

                    if (pFeature != null) break;
                }

                //If feature found, return feature and feature class feature is in.
                if (pFeature != null && pFeatureClass != null)
                {
                    pOutFeature = pFeature;
                    pOutFeatureClass = pFeatureClass;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Procedure FindApplication " + ex.Message);
            }
            finally
            {
                if (pQueryFilter != null) { Marshal.ReleaseComObject(pQueryFilter); pQueryFilter = null; }
                if (pFeatureCursor != null) { Marshal.ReleaseComObject(pFeatureCursor); pFeatureCursor = null; }
                if (pPropertySet != null) { Marshal.ReleaseComObject(pPropertySet); pPropertySet = null; }
                if (pWorkspaceFactory != null) { Marshal.ReleaseComObject(pWorkspaceFactory); pWorkspaceFactory = null; }
                if (pFeatureWorkspace != null) { Marshal.ReleaseComObject(pFeatureWorkspace); pFeatureWorkspace = null; }
                permitType = null;
            }
        }
0 Kudos
4 Replies
AlexanderGray
Occasional Contributor III
This is an oracle problem, not a code problem.  By default I think Oracle has 50 or so maximum cursors (not sure the exact number but it is low.)  Now most applications use a 1 to 5 cursors so that is ok.  ArcGIS uses much much more, I believe the recommended max is like 10 000 for an SDE database.
CarlosPiccirillo
New Contributor III
Mr. Gray,

Thanks for the reply. Do you know what I can do to fix this problem?

This is an oracle problem, not a code problem.  By default I think Oracle has 50 or so maximum cursors (not sure the exact number but it is low.)  Now most applications use a 1 to 5 cursors so that is ok.  ArcGIS uses much much more, I believe the recommended max is like 10 000 for an SDE database.
0 Kudos
CarlosPiccirillo
New Contributor III
Thanks, I'll see if I can make some sense out of it.
0 Kudos