<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Yet another Schema Lock post...error with shapefile only in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457773#M35950</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've found using functions solves a lot of ghost schema locking issues I've had.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Nov 2011 19:32:21 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2011-11-03T19:32:21Z</dc:date>
    <item>
      <title>Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457771#M35948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a script which creates several intermediate files saved into a temporary location.&amp;nbsp; The user is allowed to select this location.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My code loops through features 300 at a time, performs some geoprocessing operations, and attempts to add a field and populate it with the area geometry.&amp;nbsp; This always works the first time through.&amp;nbsp; Once I get to the second loop though, if the intermediate files are being saved into a folder as shapefiles (rather than a geodatabase as feature classes), I get a schema lock error when trying to add the field.&amp;nbsp; I have overwrite output set to True, and there are several other files in the same folder which are successfully overwritten before encountering this error.&amp;nbsp; The actual shapefile whose attribute table I am attempting to edit has, in fact, just been successfully overwritten before encountering this error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I know very little about schema locks, please help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Nov 2011 18:54:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457771#M35948</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2011-11-03T18:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457772#M35949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Could you post the script?&amp;nbsp; Or if the file is to be overwritten anyway, you could try to throw a Delete_management (see help for syntax) into the mix.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Nov 2011 19:21:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457772#M35949</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2011-11-03T19:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457773#M35950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've found using functions solves a lot of ghost schema locking issues I've had.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Nov 2011 19:32:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457773#M35950</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2011-11-03T19:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457774#M35951</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is the script, I have bolded the line that is returning the error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import modules
import arcgisscripting
import datetime

# Create geoprocessor object
gp = arcgisscripting.create(9.3)

# Get Parameters
catchments = gp.GetParameterAsText(0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Feature Class
idField = gp.GetParameterAsText(1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Field
streams = gp.GetParameterAsText(2)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Feature Class
bufferDistance = int(gp.GetParameterAsText(3))&amp;nbsp; # Long
landCover = gp.GetParameterAsText(4)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Feature Class
outFolder = gp.GetParameterAsText (5)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Workspace
tempWorkspace = gp.GetParameterAsText (6)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Workspace

gp.overwriteoutput = True
gp.Workspace = tempWorkspace
gp.ScratchWorkspace = tempWorkspace

# Set-up environment variables
desc = gp.describe (catchments)
xmin = desc.extent.xmin
ymin = desc.extent.ymin
xmax = desc.extent.xmax
ymax = desc.extent.ymax
gp.XYDomain = str(xmin - (bufferDistance*2)) + " " + str(ymin - (bufferDistance*2)) + " " + str(xmax + (bufferDistance*2)) + " " + str(ymax + (bufferDistance*2))

# Create names for geoprocessing interim files based on the type of workspace selected
wsDesc = gp.Describe(tempWorkspace)
wsType = wsDesc.WorkspaceType
# If the workspace is a folder
if wsType == "FileSystem":
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Interim files must have the ".shp" extension
&amp;nbsp;&amp;nbsp;&amp;nbsp; streamsd = "streamsd.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; catchStrm = "CatchStrm.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; catchStrmBuff = "CatchStrmBuff.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; catchStrmBuffDiss = "CatchStrmBuffDiss.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; catchStrmBuffInt = "CatchStrmBuffInt.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; selection = "Selection.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionDiss = "SelectionDiss.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionDissInt = "SelectionDissInt.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; tableName = "Rip" + str(bufferDistance) + ".shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; appendTable = "AppendMe.dbf"
# If the workspace is a geodatabase
elif wsType == "LocalDatabase": 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Interim files do not require an extension
&amp;nbsp;&amp;nbsp;&amp;nbsp; streamsd = "streamsd"
&amp;nbsp;&amp;nbsp;&amp;nbsp; catchStrm = "CatchStrm"
&amp;nbsp;&amp;nbsp;&amp;nbsp; catchStrmBuff = "CatchStrmBuff"
&amp;nbsp;&amp;nbsp;&amp;nbsp; catchStrmBuffDiss = "CatchStrmBuffDiss"
&amp;nbsp;&amp;nbsp;&amp;nbsp; catchStrmBuffInt = "CatchStrmBuffInt"
&amp;nbsp;&amp;nbsp;&amp;nbsp; selection = "Selection"
&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionDiss = "SelectionDiss"
&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionDissInt = "SelectionDissInt"
&amp;nbsp;&amp;nbsp;&amp;nbsp; tableName = "Rip" + str(bufferDistance)
&amp;nbsp;&amp;nbsp;&amp;nbsp; appendTable = "AppendMe"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Dissolve streams not allowing multipart to reduce the number of features to be buffered
gp.Dissolve_management (streams, streamsd, "", "", "SINGLE_PART", "")

# Count the total number of catchments
resultCatchments = gp.GetCount_management(catchments)
countCatchments = int(resultCatchments.GetOutput(0))

# Make a feature layer from the catchments
gp.MakeFeatureLayer_management (catchments, "CatchLayer") 

# Create a search cursor to loop through the catchments 300 at a time
rows = gp.SearchCursor (catchments)
row = rows.next()
x = 0
list = []
while x &amp;lt; countCatchments:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## If there are fewer than 300 features remaining
&amp;nbsp;&amp;nbsp;&amp;nbsp; if countCatchments - x &amp;lt;300:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; remaining = countCatchments - x
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range (0,remaining,1):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objectID = row.getvalue ("ObjectID")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = x+1
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Otherwise
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range (0,300,1):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objectID = row.getvalue("ObjectID")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = x+1
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Add the 300th, or last, ObjectID to the List
&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append (objectID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Get the ObjectIDs from the list and perform selections and geoprocessing
# How many items are in the list?
items = len(list)
for i in range (0, items, 1):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## If this is the first item on the list
&amp;nbsp;&amp;nbsp;&amp;nbsp; if i == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = '"OBJECTID" &amp;lt;= ' + str(list&lt;I&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastitem = list&lt;I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Otherwise
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = '"OBJECTID" &amp;gt; ' + str(lastitem) + ' AND "OBJECTID" &amp;lt;= ' + str(list&lt;I&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastitem = list&lt;I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerbyAttribute_management("CatchLayer", "NEW_SELECTION", query)&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Get the number of catchments selected
&amp;nbsp;&amp;nbsp;&amp;nbsp; resultSelCatch = gp.GetCount_management("CatchLayer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; countSelCatch = int(resultSelCatch.GetOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Intersect catchments and streams
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Intersect_analysis ("CatchLayer;" + streamsd, catchStrm, "ALL", "", "INPUT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; resultIntersect = gp.GetCount_management(catchStrm)
&amp;nbsp;&amp;nbsp;&amp;nbsp; countIntersect = int(resultIntersect.GetOutput(0))

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Buffer intersected catchments and streams
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.RepairGeometry_management (catchStrm)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Buffer_analysis (catchStrm, catchStrmBuff, bufferDistance, "FULL", "ROUND", "NONE")

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Dissolve the buffered streams... process may fail if this is done as part of the buffer operation
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Dissolve_management (catchStrmBuff, catchStrmBuffDiss, idField, "", "MULTI_PART", "")

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Intersect catchments and buffer
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Intersect_analysis (catchments + ";" + catchStrmBuffDiss, catchStrmBuffInt, "ALL", "", "INPUT")

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Select features where buffer ID and catchment ID are the same
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Select_analysis (catchStrmBuffInt, selection, '"'+ idField + '"="' + idField + '_1"')

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Dissolve selected features based on ID, allowing multipart
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Dissolve_management (selection, selectionDiss, idField, "", "MULTI_PART", "")

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Intersect dissolved features and land cover
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Intersect_analysis (selectionDiss + ";" + landCover, selectionDissInt, "ALL", "", "INPUT")

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Dissolve intersected features based on ID and land cover type, allowing multipart
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Dissolve_management (selectionDissInt, tableName, idField + "; SCO_Class", "", "MULTI_PART", "")

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Add field (Area)
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;gp.AddField_Management (tableName, "Area", "DOUBLE", "#", "#", "#", "", "#", "#", "")&lt;/STRONG&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Calculate area field
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management (tableName, "Area",&amp;nbsp; "!" + gp.describe(tableName).shapefieldname + ".AREA@SQUAREMETERS!", "PYTHON_9.3", "")&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; ## If this is the first set
&amp;nbsp;&amp;nbsp;&amp;nbsp; if i == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ### Export attribute table
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.TableToDBASE_conversion (tableName, outFolder)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Otherwise
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ### Export the attribute table and append it onto the existing one
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeTableView_management (tableName, "RipView")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CopyRows_management ("RipView", appendTable)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Append_management (appendTable, outFolder + "\Rip" + str(bufferDistance) + ".dbf", "NO_TEST")

# Delete the Temporary Files&amp;nbsp;&amp;nbsp;&amp;nbsp; 
gp.Delete_management (catchStrm)
gp.Delete_management (catchStrmBuff)
gp.Delete_management (catchStrmBuffInt)
gp.Delete_management (tableName)
gp.Delete_management (selection)
gp.Delete_management (selectionDiss)
#gp.Delete_management (selectionDissInt)
gp.Delete_management (streamsd)
gp.Delete_management (catchStrmBuffDiss)
gp.Delete_management (appendTable)&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:22:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457774#M35951</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2021-12-11T20:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457775#M35952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;don't have 9.3 but could you make Management in that line lower case, I can't remember if 9.3 is case-sensitive or not&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Nov 2011 20:15:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457775#M35952</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2011-11-03T20:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457776#M35953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;don't have 9.3 but could you make Management in that line lower case, I can't remember if 9.3 is case-sensitive or not&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;Tried that, still gives me the schema lock error&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I've found using functions solves a lot of ghost schema locking issues I've had.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure what you mean by this...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;you could try to throw a Delete_management (see help for syntax) into the mix.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you mean within the loop after the file is no longer needed?&amp;nbsp; I will try.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Nov 2011 12:52:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457776#M35953</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2011-11-04T12:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457777#M35954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Threw in a Delete_management after the final if-else clause and that didn't fix it either.&amp;nbsp; After the code has run, and given me the schema lock error I can go in to ArcMap, add the file in question, and add a field without encountering any locks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also tried creating a function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def AddField (fc):
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Adds a field to a feature class, hopefully removes any schema locking errors"
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddField_management (fc, "Area", "DOUBLE", "#", "#", "#", "", "#", "#", "")

....
## Add field (Area)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.AddField_management (tableName, "Area", "DOUBLE", "#", "#", "#", "", "#", "#", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; AddField(tableName)
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Same error.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:22:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457777#M35954</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2021-12-11T20:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457778#M35955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry, I wasn't very clear. You should try to put the previous GP tools in a function, the add field isn't the problem it is just encountering the lock, it is a previous tool, probably the last dissolve there, that is holding the lock.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you sure your pathnames are not too long? No other processes accessing the data?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;May be redundant, but have you tried using TestSchemaLock at various times to see where that particular shapefile is being locked and not released?&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000024000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000024000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Nov 2011 12:25:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457778#M35955</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2011-11-07T12:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457779#M35956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;On a similar vein, arcpy.Exists() seems to help clear out a lot (well... it depends) of locking issues. Hopefully it works the same for 9.3 and the GP. I.e. place:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;gp.Exists(tableName)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;just before the line that gives you the errors. This normally outputs a True or False, but in this case you don't need to worry about that - the mere fact that it queries for the file should be sufficient.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 04:40:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457779#M35956</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2011-11-10T04:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457780#M35957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks a lot for your help everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried a combination of what you suggested.&amp;nbsp; I went through all my code and tested for schema locks with gp.TestSchemaLock before every geoprocess.&amp;nbsp; If one was available I went through the process, if one was not available I printed a message saying "unable to get schema lock for file name".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;By doing this I found that the second process I run (Make feature layer) will not release it's schema lock so I have been using your tips to try and release this lock.&amp;nbsp; I have created a function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Define any functions necessary to avoid schema locks
## Create a feature layer from catchments
def MakeFL (catch):
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Makes a feature layer from the input... hopefully a schema lock will be available for this layer"
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer_management (catch, "CatchLayer")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and used it to make a feature layer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Make a feature layer from the catchments
#gp.MakeFeatureLayer_management (catchments, "CatchLayer")
MakeFL (catchments)
exists = gp.exists ("CatchLayer")
print "Was 'CatchLayer' created? " + str(exists)
lockTest = gp.TestSchemaLock ("CatchLayer")
print "A schema lock is available for 'CatchLayer' immediately afer it is created: " + str(lockTest)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This line : "print "Was 'CatchLayer' created? " + str(exists)" returns 'true' proving that the function does actually create a layer.&amp;nbsp; The line : "print "A schema lock is available for 'CatchLayer' immediately afer it is created: " + str(lockTest)" returns "false" showing that even though I used a function to create it, a schema lock is still not available for this layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I even deleted my workspace folder and re-created it to make sure that there were no files in there getting mixed up from a previous run of the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you please let me know if I have implemented your suggestions correctly, and if I have, do you have any others?? &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank-you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:22:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457780#M35957</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2021-12-11T20:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457781#M35958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;Could you please let me know if I have implemented your suggestions correctly, and if I have, do you have any others?? &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;BR /&gt;Thank-you!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am theorizing that the search cursor is holding onto the editing rights of a shape file. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After the end of your search cursor loop add the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;del row
del rows&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe that should free it up and hopefully drop the schema lock.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:22:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457781#M35958</guid>
      <dc:creator>JamesHood</dc:creator>
      <dc:date>2021-12-11T20:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457782#M35959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have found that I don't need to be able to get a schema lock on the feature layer I created (CatchLayer) in order for the code to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I added the lines del row and del rows.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am still getting a cannot get exclusive schema lock error, in the following section:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lockTest = gp.TestSchemaLock (selectionDissInt)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lockTest:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Dissolve intersected features based on ID and land cover type, allowing multipart
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Dissolve_management (selectionDissInt, tableName, idField + "; SCO_Class", "", "MULTI_PART", "") # &amp;lt;---- Fail
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "dissolved intersected features based on ID and land cover type, allowing multipart"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "unable to get schema lock on selectionDissInt"&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;which is weird because it is only supposed to run the code once it is established that a schema lock is available...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:22:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457782#M35959</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2021-12-11T20:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457783#M35960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I now seem to be getting a sort of intermittent error.&amp;nbsp; Sometimes the dissolve in the code snippet above will work, and sometimes it won't, sometimes it will fail on the 3rd loop.&amp;nbsp; If it does work, the next process, Add Field, will (sometimes) be unable to acquire a schema lock.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Just now, for example, during the first loop, everything worked, during the second loop the dissolve worked, and the add field and calculate field were unable to obtain a schema lock, and during the 3rd loop the dissolve failed (it still got through the if TestSchemaLock: part, but then failed with a schema lock error).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried the following to try and fix the schema locking error, all to no avail:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Restart computer, clean out temp folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Create new folder to store interim files&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Create new folder to set as scratch workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Add del row and del rows line after search cursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Run every process as a separate function&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Create short interim file names (a,b,c,d etc...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Save all outputs to a location with a short path (F:\Lorna\Temp)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- I am not running ArcCatalog or ArcMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Copy the "locked" file using CopyFeatures_management before running dissolve&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have no more ideas to try.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2011 12:19:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457783#M35960</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2011-12-09T12:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another Schema Lock post...error with shapefile only</title>
      <link>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457784#M35961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I managed to solve this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It was the same problem as discussed in &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/28796-Table-view-causing-schema-lock?highlight=schema+lock"&gt;this&lt;/A&gt;&lt;SPAN&gt; thread&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The table view was causing the issue.&amp;nbsp; It has to have a different name each time it is created.&amp;nbsp; My solution was not to use a time stamp as discussed in the above thread, but to use the i variable from my loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code excerpt where I create a name for the table view.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if wsType == "FileSystem":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; finalShp = "Rip" + str(bufferDistance) + "_" + str(i) + ".shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif wsType == "LocalDatabase":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; finalShp = "Rip" + str(bufferDistance) + "_" + str(i)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...&lt;PRE&gt; tags are not formatting my tabs properly.&lt;/PRE&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 14:37:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/yet-another-schema-lock-post-error-with-shapefile/m-p/457784#M35961</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2012-01-06T14:37:17Z</dc:date>
    </item>
  </channel>
</rss>

