<?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 ArcSDESQLExecute is not able to DELETE rows in one database but works in other in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-is-not-able-to-delete-rows-in-one/m-p/1000609#M59019</link>
    <description>&lt;P&gt;I have two ESRI enterprise geodatabases on SQLServer: A and B. They are almost the same database (structure)&lt;/P&gt;&lt;P&gt;I have this code snippet in python to deleted several rows from versions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def delete_project_features(edit_workspace, delete_tables, version, inspection_id):
sde_conn = arcpy.ArcSDESQLExecute(edit_workspace)

sde_conn.execute("EXEC sde.set_current_version '{0}';".format(version))
sde_conn.execute("EXEC sde.edit_version '{0}',1 WITH RESULT SETS NONE;".format(version))

for table in delete_tables: 
inspectionId = inspection_id
feature_count = sde_conn.execute("SELECT COUNT(*) FROM {0}_evw WHERE INSPECTION_ID = '{1}';".format(table, inspectionId))
sde_conn.execute("DELETE FROM {0}_evw WHERE INSPECTION_ID = '{1}';".format(table, inspectionId)) 
try: 
sde_conn.execute("EXEC sde.edit_version '{0}',2 WITH RESULT SETS NONE;".format(version))

except Exception as e:
if repr(e).find("error 266") &amp;gt; -1:
logEngine.log(_("Deleted all redundant features"), logger, SERVICE)
else:
mess = "Failed to delete features"
raise Exception(mess)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;When I run it on Database A, the rows are deleted as expected, but in Database B the rows remain there.&lt;/P&gt;&lt;P&gt;I always get the error:&lt;/P&gt;&lt;P&gt;AttributeError: ArcSDESQLExecute: StreamExecute ArcSDE Extended error 266 [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0.&lt;/P&gt;&lt;P&gt;despite the fact of the error, the rows are deleted on A&lt;/P&gt;&lt;P&gt;What setting could be different in the databases that prevents in B the successful result of the script execution?&lt;/P&gt;&lt;P&gt;Database A:&lt;BR /&gt;Compatibility level 2016&lt;BR /&gt;Recovery model Simple&lt;BR /&gt;Collation SQL_Latin1_General_CP1_CI_AS&lt;/P&gt;&lt;P&gt;Database B:&lt;BR /&gt;Compatibility level 2012&lt;BR /&gt;Recovery model Full&lt;BR /&gt;Collation Latin1_General_CI_AS&lt;/P&gt;</description>
    <pubDate>Thu, 12 Nov 2020 11:23:53 GMT</pubDate>
    <dc:creator>Cristian_Galindo</dc:creator>
    <dc:date>2020-11-12T11:23:53Z</dc:date>
    <item>
      <title>ArcSDESQLExecute is not able to DELETE rows in one database but works in other</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-is-not-able-to-delete-rows-in-one/m-p/1000609#M59019</link>
      <description>&lt;P&gt;I have two ESRI enterprise geodatabases on SQLServer: A and B. They are almost the same database (structure)&lt;/P&gt;&lt;P&gt;I have this code snippet in python to deleted several rows from versions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def delete_project_features(edit_workspace, delete_tables, version, inspection_id):
sde_conn = arcpy.ArcSDESQLExecute(edit_workspace)

sde_conn.execute("EXEC sde.set_current_version '{0}';".format(version))
sde_conn.execute("EXEC sde.edit_version '{0}',1 WITH RESULT SETS NONE;".format(version))

for table in delete_tables: 
inspectionId = inspection_id
feature_count = sde_conn.execute("SELECT COUNT(*) FROM {0}_evw WHERE INSPECTION_ID = '{1}';".format(table, inspectionId))
sde_conn.execute("DELETE FROM {0}_evw WHERE INSPECTION_ID = '{1}';".format(table, inspectionId)) 
try: 
sde_conn.execute("EXEC sde.edit_version '{0}',2 WITH RESULT SETS NONE;".format(version))

except Exception as e:
if repr(e).find("error 266") &amp;gt; -1:
logEngine.log(_("Deleted all redundant features"), logger, SERVICE)
else:
mess = "Failed to delete features"
raise Exception(mess)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;When I run it on Database A, the rows are deleted as expected, but in Database B the rows remain there.&lt;/P&gt;&lt;P&gt;I always get the error:&lt;/P&gt;&lt;P&gt;AttributeError: ArcSDESQLExecute: StreamExecute ArcSDE Extended error 266 [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0.&lt;/P&gt;&lt;P&gt;despite the fact of the error, the rows are deleted on A&lt;/P&gt;&lt;P&gt;What setting could be different in the databases that prevents in B the successful result of the script execution?&lt;/P&gt;&lt;P&gt;Database A:&lt;BR /&gt;Compatibility level 2016&lt;BR /&gt;Recovery model Simple&lt;BR /&gt;Collation SQL_Latin1_General_CP1_CI_AS&lt;/P&gt;&lt;P&gt;Database B:&lt;BR /&gt;Compatibility level 2012&lt;BR /&gt;Recovery model Full&lt;BR /&gt;Collation Latin1_General_CI_AS&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 11:23:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-is-not-able-to-delete-rows-in-one/m-p/1000609#M59019</guid>
      <dc:creator>Cristian_Galindo</dc:creator>
      <dc:date>2020-11-12T11:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDESQLExecute is not able to DELETE rows in one database but works in other</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-is-not-able-to-delete-rows-in-one/m-p/1001001#M59037</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/104075"&gt;@Cristian_Galindo&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;It seems that Database B was constructed on an earlier version of SQL that could be having an impact in the connection.&amp;nbsp; Arc is not finding any Commit statements after it sends the changes through.&lt;/P&gt;&lt;P&gt;Here is an article from 2017 where the person is having the same/similar issue:&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/248064/arcsdesqlexecute-mismatching-number-of-begin-and-commit-statements" target="_blank"&gt;https://gis.stackexchange.com/questions/248064/arcsdesqlexecute-mismatching-number-of-begin-and-commit-statements&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These may also be of help, but probably not as much:&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.esri.com/en/technical-article/000010759" target="_blank"&gt;https://support.esri.com/en/technical-article/000010759&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/sql/connect/odbc/windows/system-requirements-installation-and-driver-files?view=sql-server-ver15" target="_blank"&gt;https://docs.microsoft.com/en-us/sql/connect/odbc/windows/system-requirements-installation-and-driver-files?view=sql-server-ver15&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope you find you answer,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 02:37:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-is-not-able-to-delete-rows-in-one/m-p/1001001#M59037</guid>
      <dc:creator>Michael_Boyce</dc:creator>
      <dc:date>2020-11-13T02:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDESQLExecute is not able to DELETE rows in one database but works in other</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-is-not-able-to-delete-rows-in-one/m-p/1001185#M59040</link>
      <description>&lt;P&gt;The issue looks similar, but despite the fact that I receive the same error, in database A the changes are committed.&lt;/P&gt;&lt;P&gt;Reading the suggested links, I am doing both calls from the same computer, and i have both databases in the same instance of SQLServer.&lt;/P&gt;&lt;P&gt;I am going to try changing the compatibility of the database.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 13:20:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-is-not-able-to-delete-rows-in-one/m-p/1001185#M59040</guid>
      <dc:creator>Cristian_Galindo</dc:creator>
      <dc:date>2020-11-13T13:20:16Z</dc:date>
    </item>
  </channel>
</rss>

