<?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: Delete Specific Feature Class in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154104#M64066</link>
    <description>&lt;P&gt;I've never found a good way to get around this from python. Usually when my script fails (and I know nobody else should be using the database) I delete the locks on the database and then rerun the script. There is probably a less disruptive way - I'd be curious to find out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DonMorrison1_0-1647386291979.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/36438i0020ED963F06F544/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DonMorrison1_0-1647386291979.png" alt="DonMorrison1_0-1647386291979.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Mar 2022 23:19:27 GMT</pubDate>
    <dc:creator>DonMorrison1</dc:creator>
    <dc:date>2022-03-15T23:19:27Z</dc:date>
    <item>
      <title>Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154091#M64065</link>
      <description>&lt;P&gt;I am trying to read my SDE database and then delete specific feature classes if they exist...&lt;/P&gt;&lt;P&gt;I keep getting error below....not sure whats up....do I need to make a different connection to the db?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ExecuteError: ERROR 000601: Cannot delete C:/GIS_Scripts/Update/OS@Connection.sde/database.DBO.FEATURES_update. May be locked by another application.&lt;BR /&gt;Failed to execute (Delete).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def main():
    sqlPath  = r"C:/GIS_Scripts/Update/OS@Connection.sde/"
    fc_Delete = ["database.DBO.FEATURES_update","fc_Out2a"]

    for fc in fc_Delete:
             
      fc_path = os.path.join(sqlPath, fc)
      print fc_path
      
      if arcpy.Exists(fc_path):
        arcpy.Delete_management(fc_path)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 22:35:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154091#M64065</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-03-15T22:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154104#M64066</link>
      <description>&lt;P&gt;I've never found a good way to get around this from python. Usually when my script fails (and I know nobody else should be using the database) I delete the locks on the database and then rerun the script. There is probably a less disruptive way - I'd be curious to find out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DonMorrison1_0-1647386291979.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/36438i0020ED963F06F544/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DonMorrison1_0-1647386291979.png" alt="DonMorrison1_0-1647386291979.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 23:19:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154104#M64066</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-03-15T23:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154108#M64068</link>
      <description>&lt;P&gt;Do either of these feature classes exist:&lt;/P&gt;&lt;P&gt;C:/GIS_Scripts/Update/OS@Connection.sde/database.DBO.FEATURES_update&lt;BR /&gt;C:/GIS_Scripts/Update/OS@Connection.sde/fc_Out2a&lt;/P&gt;&lt;P&gt;as that is what is being told to delete (in that order).&lt;/P&gt;&lt;P&gt;Otherwise, normally when data is locked, it is by another user OR a service that is consuming the feature class.&lt;/P&gt;&lt;P&gt;You need to make sure you stop any services that are using that feature class.&amp;nbsp; If that isn't it, you can try to &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/arcpy/functions/disconnectuser.htm" target="_self"&gt;disconnect users&lt;/A&gt; from the database, and, maybe even &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/arcpy/functions/acceptconnections.htm" target="_self"&gt;block incoming connections&lt;/A&gt; while you do the delete.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 23:36:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154108#M64068</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-03-15T23:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154210#M64069</link>
      <description>&lt;P&gt;The dbo.features_update FC exists....&lt;/P&gt;&lt;P&gt;Thats the crazy thing there are no locks....&lt;/P&gt;&lt;P&gt;That is ALL the code that I am trying to use....is there something else that I am missing....&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jaykapalczynski_0-1647433819394.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/36465iC174AEFFAAC99D75/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jaykapalczynski_0-1647433819394.png" alt="jaykapalczynski_0-1647433819394.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jaykapalczynski_1-1647433838856.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/36466i2D99DCB49EFE65C9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jaykapalczynski_1-1647433838856.png" alt="jaykapalczynski_1-1647433838856.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 12:32:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154210#M64069</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-03-16T12:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154214#M64070</link>
      <description>&lt;P&gt;It almost appears that its creating its own lock when its trying to read if it exists....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 12:39:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154214#M64070</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-03-16T12:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154227#M64071</link>
      <description>&lt;P&gt;My first thought is are you using the connection for the data owner? Most of the time it will be the sde account. Not sure what your OS connection has available in terms of roles, but that is something to check as well.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 12:58:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154227#M64071</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-03-16T12:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154228#M64072</link>
      <description>&lt;P&gt;I would try to delete the table using the Delete Geoprocessing tool in ArcGIS Pro to see if you can establish that&amp;nbsp; it is related to something in your python code.&amp;nbsp; Another possibility is something in the database itself has it locked. Our systems use MS SQL Server and I would guess there are things you could do in the MS SQL Server Manager that would lock up a table. I've never had a problem with the arcpy.Exists call leaving the object locked.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 12:59:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154228#M64072</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-03-16T12:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154231#M64073</link>
      <description>&lt;P&gt;OK so its telling me its locked but I have already cleared the locks....there is no service hitting this db and its on a test box so nothing should be accessing it....&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I first check to make sure it exists&lt;/LI&gt;&lt;LI&gt;I then try to disconnect all users&lt;/LI&gt;&lt;LI&gt;I then test that specific FC for a lock&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It keeps telling me its locked but when I check the DB and FC after it runs there are no locks?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    for fc in fc_Delete:
             
      fc_path = os.path.join(workspaceLocation, fc)
      print fc_path
      if arcpy.Exists(fc_path):
          arcpy.DisconnectUser(r"C:/GIS_Scripts/Update/OSConnection.sde/", "ALL")
          print fc_path + " exists"
          if not arcpy.TestSchemaLock(fc_path):
            print "Can't proceed - " + fc_path + " feature class is locked"
          else:
            arcpy.ClearWorkspaceCache_management()
            arcpy.Delete_management(fc_path)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 13:06:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154231#M64073</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-03-16T13:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154252#M64074</link>
      <description>&lt;P&gt;Thanks will check that out....&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 13:48:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1154252#M64074</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-03-16T13:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1155204#M64113</link>
      <description>&lt;P&gt;Thanks Ya'll for your comments....turns out there was an issue with the FC itself.&amp;nbsp; I rebuilt the db and everything works regarding the DELETE....thanks again&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2022 12:48:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1155204#M64113</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-03-18T12:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Specific Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1222951#M65875</link>
      <description>&lt;P&gt;I got this Traceback from an exception from &lt;EM&gt;arcpy.management.Delete&lt;/EM&gt;:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  [...TRIMMED THE SAUSAGE-MAKING OF MY SCRIPTS...]
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 6977, in Delete
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 6974, in Delete
    retval = convertArcObjectToPythonObject(gp.Delete_management(*gp_fixargs((in_data, data_type), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000601: Cannot delete &amp;lt;PATH_TO_SDE_FILE&amp;gt;\&amp;lt;DATABASE&amp;gt;.&amp;lt;SCHEMA&amp;gt;.&amp;lt;FEATURE_CLASS&amp;gt;.  May be locked by another application.
Underlying DBMS error [42S02:[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot drop the procedure 'DBO.i68_return_ids', because it does not exist or you do not have permission.] [&amp;lt;DATABASE&amp;gt;.&amp;lt;SCHEMA&amp;gt;.&amp;lt;FEATURE_CLASS&amp;gt;]
Failed to execute (Delete).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had another table that I had created using non-Esri SQL. That table had a foreign key referencing my feature class. Because the table and FK were both created with SQL, I guess SDE doesn't know about them, so wasn't tracking them, and thus was unable to delete the feature class with another table referencing it. As soon as I dropped the FK, the error went away.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know we're supposed to always use Esri tools to manage database objects related to feature classes, but this seems like such a basic thing that it surprised me that arcpy's Delete couldn't figure it out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 18:11:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-specific-feature-class/m-p/1222951#M65875</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2022-10-18T18:11:08Z</dc:date>
    </item>
  </channel>
</rss>

