<?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 Executing Stored Procedure from Python in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/executing-stored-procedure-from-python/m-p/217212#M1364</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greetings!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to run a stored procedure (with a parameter)&amp;nbsp;from a python script.&amp;nbsp; The stored procedure joins some tables and inserts a record from the joined tables&amp;nbsp;into another table.&amp;nbsp; The stored procedure works fine when I execute it from within Microsoft SQL Server Management Studio.&amp;nbsp;When I run the stored procedure from Python, it inserts the record... but it inserts it&amp;nbsp;3 times!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the snippet of code from Python:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;db_connection = arcpy.ArcSDESQLExecute ("path to the SQL connection file")&lt;/P&gt;&lt;P&gt;sql = "EXEC dbo.MyStoredProcedure @id = 1"&lt;/P&gt;&lt;P&gt;db_connection.execute(sql)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additional info:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; The table and stored procedure are not in with our SDE.&amp;nbsp; It's in a separate "non-GIS" database.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; I'm using Python because I'm taking the record that is generated in the stored procedure and will be&amp;nbsp;using it in geoprocessing tasks on down the line.&lt;/P&gt;&lt;P&gt;3. SQL Server 2008 R2&lt;/P&gt;&lt;P&gt;4.&amp;nbsp; ArcGIS 10.3.1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas as to why it is as if the stored procedure is being executed 3 times when called from Python?&amp;nbsp; Is there a better way to execute the stored procedure?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Stephanie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Nov 2016 19:10:41 GMT</pubDate>
    <dc:creator>StephanieWidas</dc:creator>
    <dc:date>2016-11-28T19:10:41Z</dc:date>
    <item>
      <title>Executing Stored Procedure from Python</title>
      <link>https://community.esri.com/t5/developers-questions/executing-stored-procedure-from-python/m-p/217212#M1364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greetings!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to run a stored procedure (with a parameter)&amp;nbsp;from a python script.&amp;nbsp; The stored procedure joins some tables and inserts a record from the joined tables&amp;nbsp;into another table.&amp;nbsp; The stored procedure works fine when I execute it from within Microsoft SQL Server Management Studio.&amp;nbsp;When I run the stored procedure from Python, it inserts the record... but it inserts it&amp;nbsp;3 times!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the snippet of code from Python:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;db_connection = arcpy.ArcSDESQLExecute ("path to the SQL connection file")&lt;/P&gt;&lt;P&gt;sql = "EXEC dbo.MyStoredProcedure @id = 1"&lt;/P&gt;&lt;P&gt;db_connection.execute(sql)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additional info:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; The table and stored procedure are not in with our SDE.&amp;nbsp; It's in a separate "non-GIS" database.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; I'm using Python because I'm taking the record that is generated in the stored procedure and will be&amp;nbsp;using it in geoprocessing tasks on down the line.&lt;/P&gt;&lt;P&gt;3. SQL Server 2008 R2&lt;/P&gt;&lt;P&gt;4.&amp;nbsp; ArcGIS 10.3.1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas as to why it is as if the stored procedure is being executed 3 times when called from Python?&amp;nbsp; Is there a better way to execute the stored procedure?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Stephanie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Nov 2016 19:10:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/executing-stored-procedure-from-python/m-p/217212#M1364</guid>
      <dc:creator>StephanieWidas</dc:creator>
      <dc:date>2016-11-28T19:10:41Z</dc:date>
    </item>
  </channel>
</rss>

