How to get exclusive schema lock

Discussion created by grse26 on Aug 24, 2010
Latest reply on Aug 26, 2010 by grse26
I am trying to write code that will run the 'Extract Values To Points' procedure against every raster in a selected set.  That portion of my code works, but I suspect I am making errors when I reuse object variables.  After the extraction loop completes, I want to add X- and Y- coordinates to the last feature class that was created.  I have been unable to get that to work.  Even if I exit the code and try running the 'AddXY' tool from the same project, I get: "ERROR 000464: Cannot get exclusive schema lock...".  However, if I open a new project and add that feature class, then there is no problem with the 'AddXY' tool.

Why am I unable to add the coordinates in the first case?  Is there a way to 'free' that feature class from whatever is not allowing the coordinates to be added?  Many thanks in advance.

That portion of my code follows:
    Dim pLayer As ILayer
    Dim pFLayer As IFeatureLayer
    Set pFLayer = New FeatureLayer
    Dim pWkFactory As IWorkspaceFactory
    Set pWkFactory = New ShapefileWorkspaceFactory
    Dim pFWkSpace As IFeatureWorkspace
    Dim pFClass As IFeatureClass

    Dim pFields As IFields
    Dim pField As IField
    Dim pFieldEdit As IFieldEdit
    'Load selected layer (FLResponse was NOT dimensioned)
    FLResponse = cboResponse.Value
    'Iterate through selected covariates
    For i = 0 To lboCovariate.ListCount - 1
        'Path and name of shapefile to be created
        fileExtract = tmpFolder & "\UseExtraction" & i & ".shp"

        'Load each covariate layer
        RLCovarTif = lboCovariate.List(i)

        ' Process: Extract Values to Points...
        If i = 0 Then
            gp.ExtractValuesToPoints_sa FLResponse, RLCovarTif, fileExtract, "NONE", "VALUE_ONLY"
            gp.ExtractValuesToPoints_sa pFClass2, RLCovarTif, fileExtract, "NONE", "VALUE_ONLY"
        End If

        FLResponse = "UseExtraction" & i
        'Delete new layer from project
        For j = 0 To pMap.LayerCount - 1
            If (pMap.Layer(j).Name) = (FLResponse) Then
                pMap.DeleteLayer pMap.Layer(j)
                Exit For
            End If
        Next j
        'Load most recent extraction point layer
        Set pFWkSpace = pWkFactory.OpenFromFile(tmpFolder & "\", 0)
        Set pFClass = pFWkSpace.OpenFeatureClass(FLResponse)

        'Get all fields and change name of extracted raster field
        'This is done so that another raster field can be added
        Set pFields = pFClass.Fields
        Set pField = pFields.Field(pFields.FindField("RASTERVALU"))
        Set pFieldEdit = pField
        pFieldEdit.Name = "RasVal" & i
    Next i

    'Add last shapefile to map
    'I suspect that some of this code is unnecessary
    Set pFLayer.FeatureClass = pFClass
    pFLayer.Name = FLResponse
    pMap.AddLayer pFLayer
    For j = 0 To pMap.LayerCount - 1
        If (pMap.Layer(j).Name) = (FLResponse) Then
            Set pLayer = pMap.Layer(j)
            Exit For
        End If
    Set pFLayer = pLayer
    FLResponse = pLayer.Name

    'This next line does not add POINT_X and POINT_Y fields
    'Even if I exit the code and try running AddXY tool (ArcToolbox) I get an error:
    'Error 000464: Cannot get exclusive schema lock. Either being edited
    'or in use by another application. Failed to execute (AddXY).
    'However, if I close out of the project, open a new project, and open the
    'feature layer that was most recently created, I see all of the expected
    'fields (though the last field has the original field name) and can then
    'execute the AddXY tool.
    gp.AddXY_management FLResponse