cpicciri

ORA-01000: maximum open cursors exceeded

Discussion created by cpicciri on Jul 19, 2011
Latest reply on Jul 19, 2011 by cpicciri
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[i];
                    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;
            }
        }

Outcomes