IDataset / 2147467259 HResult COM Error

2599
1
03-11-2013 09:00 AM
AnikaMeyer
New Contributor
Dear everybody:

I have problems with this line of code:

            pDS = pGPUtils.OpenFeatureClassFromString(ruta & outname)

The error message is in spanish:
"-2147467259 Devuelto error HRESULT E-Fail de una llamada a un componente COM"

You may see in the complete code that the code makes a selection of a combination of Featureclass-joined table. The sql-string gets one value of the for-next-structure and finally it checks if some records are selected. Only if their are some records selected it exports the selected records to a new shape.

This boocle is correct only for 1 selection. Once a shapfile is exported and the boocle repeats I get this error mentioned above in the following line of code:
pDS = pGPUtils.OpenFeatureClassFromString(ruta & outname)

What is wrong with the IDataset? Shall I initialize every time the boocle repeats? Their seems to be a COM problem but I don´t know what kind of?

Thanks very much for your help!!

Anika


Sub ExportSelectedFeatures_HabTodos_Bio()
        ' ---- Output Shapefile Name ----
        ' -------------------------------
        Dim pGPUtils As IGPUtilities
        Dim pDS As IDataset
        Dim pMxDoc As IMxDocument
        Dim pMap As IMap
        Dim pFeatSel As IFeatureSelection
        Dim pGeoFtrLyr As IGeoFeatureLayer
        Dim pFtrCls As IFeatureClass
        Dim pExportOp As IExportOperation
        Dim pInDsName As IDatasetName
        Dim pOutFCName As IFeatureClassName
        Dim pQryFltr As IQueryFilter
        Dim pClone As IClone
        Dim pGeomDef As IGeometryDef
        Dim lShpFldIdx As Long
        Dim pSelSet As ISelectionSet

        Dim numlstbio As Integer
        Dim k As Integer

        Dim sql1 As String

        pMxDoc = My.ArcMap.Document
        pMap = pMxDoc.FocusMap

        ' Use GPUtilities to delete the shapefile if it exists
        pGPUtils = New GPUtilities
        On Error Resume Next

        pFeatSel = pMap.Layer(numerolayer)
        pGeoFtrLyr = pFeatSel

        pFtrCls = pGeoFtrLyr.DisplayFeatureClass

        numlstbio = Me.lstBio.Items.Count

        ' Create the Query
        pQryFltr = New QueryFilter

        For k = 0 To numlstbio - 1


            nomlstbio = Me.lstBio.Items.Item(k)

            Select Case numerolayer
                Case Is = 0
                    outname = strCodUE & "_" & nombresigla & "_" & strDescCodHabit & "_" & nomlstbio & "_InvHab25.shp"
                    sql1 = "GIS_HAB25000_Etrs89_UTMBio.REGBIO = '" & nomlstbio & "' AND t" & nombresigla & ".CodHABITTODOS = '" & nombresigla & "'"
                    pQryFltr.WhereClause = sql1
                Case Is = 1
                    outname = strCodUE & "_" & nombresigla & "_" & strDescCodHabit & "_" & nomlstbio & "_InvHabFlu.shp"
                    sql1 = "GIS_HabFlu_licsley_Etrs89_UTMBIO.REGBIO = '" & nomlstbio & "' AND t" & nombresigla & ".CodHABITTODOS = '" & nombresigla & "'"
                    pQryFltr.WhereClause = sql1
                Case Is = 2
                    outname = strCodUE & "_" & nombresigla & "_" & strDescCodHabit & "_" & nomlstbio & "_InvHabHum.shp"
                    sql1 = "GIS_HabHum_Etrs89_UTMBIO.REGBIO = '" & nomlstbio & "' AND t" & nombresigla & ".CodHABITTODOS = '" & nombresigla & "'"
                    pQryFltr.WhereClause = sql1
            End Select

            pFeatSel.SelectFeatures(pQryFltr, esriSelectionResultEnum.esriSelectionResultNew, False)
            pFeatSel.SelectionChanged()

            pSelSet = pFeatSel.SelectionSet

            ' Use GPUtilities to delete the shapefile if it exists
            pDS = pGPUtils.OpenFeatureClassFromString(ruta & outname)
            If Err.Number = 0 Then pDS.Delete()
            On Error GoTo 0

            If pSelSet.Count > 0 Then

                ' Create the output Featureclass Name
                pOutFCName = pGPUtils.CreateFeatureClassName(ruta & outname)

                pDS = pFtrCls
                ' Get the Input Dataset Name
                pInDsName = pDS.FullName

                '#################################
                lShpFldIdx = pFtrCls.FindField(pFtrCls.ShapeFieldName)
                pGeomDef = pFtrCls.Fields.Field(lShpFldIdx).GeometryDef

                ' Execute the export operation
                pExportOp = New ExportOperation
                pExportOp.ExportFeatureClass(pInDsName, pQryFltr, Nothing, pGeomDef, pOutFCName, 0)
                pMxDoc.ActiveView.Refresh()

            End If

        Next

    End Sub
0 Kudos
1 Reply
KevinYanuk
Occasional Contributor
Dear everybody:

I have problems with this line of code:

            pDS = pGPUtils.OpenFeatureClassFromString(ruta & outname)

The error message is in spanish:
"-2147467259 Devuelto error HRESULT E-Fail de una llamada a un componente COM"

You may see in the complete code that the code makes a selection of a combination of Featureclass-joined table. The sql-string gets one value of the for-next-structure and finally it checks if some records are selected. Only if their are some records selected it exports the selected records to a new shape.

This boocle is correct only for 1 selection. Once a shapfile is exported and the boocle repeats I get this error mentioned above in the following line of code:
pDS = pGPUtils.OpenFeatureClassFromString(ruta & outname)

What is wrong with the IDataset? Shall I initialize every time the boocle repeats? Their seems to be a COM problem but I don´t know what kind of?

Thanks very much for your help!!

Anika


Sub ExportSelectedFeatures_HabTodos_Bio()
        ' ---- Output Shapefile Name ----
        ' -------------------------------
        Dim pGPUtils As IGPUtilities
        Dim pDS As IDataset
        Dim pMxDoc As IMxDocument
        Dim pMap As IMap
        Dim pFeatSel As IFeatureSelection
        Dim pGeoFtrLyr As IGeoFeatureLayer
        Dim pFtrCls As IFeatureClass
        Dim pExportOp As IExportOperation
        Dim pInDsName As IDatasetName
        Dim pOutFCName As IFeatureClassName
        Dim pQryFltr As IQueryFilter
        Dim pClone As IClone
        Dim pGeomDef As IGeometryDef
        Dim lShpFldIdx As Long
        Dim pSelSet As ISelectionSet

        Dim numlstbio As Integer
        Dim k As Integer

        Dim sql1 As String

        pMxDoc = My.ArcMap.Document
        pMap = pMxDoc.FocusMap

        ' Use GPUtilities to delete the shapefile if it exists
        pGPUtils = New GPUtilities
        On Error Resume Next

        pFeatSel = pMap.Layer(numerolayer)
        pGeoFtrLyr = pFeatSel

        pFtrCls = pGeoFtrLyr.DisplayFeatureClass

        numlstbio = Me.lstBio.Items.Count

        ' Create the Query
        pQryFltr = New QueryFilter

        For k = 0 To numlstbio - 1


            nomlstbio = Me.lstBio.Items.Item(k)

            Select Case numerolayer
                Case Is = 0
                    outname = strCodUE & "_" & nombresigla & "_" & strDescCodHabit & "_" & nomlstbio & "_InvHab25.shp"
                    sql1 = "GIS_HAB25000_Etrs89_UTMBio.REGBIO = '" & nomlstbio & "' AND t" & nombresigla & ".CodHABITTODOS = '" & nombresigla & "'"
                    pQryFltr.WhereClause = sql1
                Case Is = 1
                    outname = strCodUE & "_" & nombresigla & "_" & strDescCodHabit & "_" & nomlstbio & "_InvHabFlu.shp"
                    sql1 = "GIS_HabFlu_licsley_Etrs89_UTMBIO.REGBIO = '" & nomlstbio & "' AND t" & nombresigla & ".CodHABITTODOS = '" & nombresigla & "'"
                    pQryFltr.WhereClause = sql1
                Case Is = 2
                    outname = strCodUE & "_" & nombresigla & "_" & strDescCodHabit & "_" & nomlstbio & "_InvHabHum.shp"
                    sql1 = "GIS_HabHum_Etrs89_UTMBIO.REGBIO = '" & nomlstbio & "' AND t" & nombresigla & ".CodHABITTODOS = '" & nombresigla & "'"
                    pQryFltr.WhereClause = sql1
            End Select

            pFeatSel.SelectFeatures(pQryFltr, esriSelectionResultEnum.esriSelectionResultNew, False)
            pFeatSel.SelectionChanged()

            pSelSet = pFeatSel.SelectionSet

            ' Use GPUtilities to delete the shapefile if it exists
            pDS = pGPUtils.OpenFeatureClassFromString(ruta & outname)
            If Err.Number = 0 Then pDS.Delete()
            On Error GoTo 0

            If pSelSet.Count > 0 Then

                ' Create the output Featureclass Name
                pOutFCName = pGPUtils.CreateFeatureClassName(ruta & outname)

                pDS = pFtrCls
                ' Get the Input Dataset Name
                pInDsName = pDS.FullName

                '#################################
                lShpFldIdx = pFtrCls.FindField(pFtrCls.ShapeFieldName)
                pGeomDef = pFtrCls.Fields.Field(lShpFldIdx).GeometryDef

                ' Execute the export operation
                pExportOp = New ExportOperation
                pExportOp.ExportFeatureClass(pInDsName, pQryFltr, Nothing, pGeomDef, pOutFCName, 0)
                pMxDoc.ActiveView.Refresh()

            End If

        Next

    End Sub



You say ->  ' Use GPUtilities to delete the shapefile if it exists


Are you sure that it exists?

Is this an ArcMap Add-In ?  Perhaps you need to remove the layer from ArcMap before attempting to delete it.  Layers in ArcMap will behave a little differently than FeatureClasses - Perhaps find the layer using IFeatureLayer instead.
0 Kudos