<?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: Error Updating SQL Server Table using pyodbc in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-updating-sql-server-table-using-pyodbc/m-p/28231#M2152</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for catching that.&amp;nbsp; Apparently I needed another cup of coffee that day.&amp;nbsp; Once I added the iteration,everything worked.&amp;nbsp; Thank you, Joshua.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 Jan 2019 17:46:25 GMT</pubDate>
    <dc:creator>LucasMurray2</dc:creator>
    <dc:date>2019-01-23T17:46:25Z</dc:date>
    <item>
      <title>Error Updating SQL Server Table using pyodbc</title>
      <link>https://community.esri.com/t5/python-questions/error-updating-sql-server-table-using-pyodbc/m-p/28229#M2150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;A customer of mine has set up a SQL Server table with address, latitude, and longitude fields.&amp;nbsp; They've asked me to geocode the addresses and populate the latitude and longitude fields with the results.&amp;nbsp; This is a non-spatial table.&amp;nbsp; They plan to use the lat/long values in other, non-ESRI, applications.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've already got a process that will read the addresses from the SQL Server table, geocode them, and save the results into a feature class within a file geodatabase.&amp;nbsp; I'm trying to build a python script that will update the SQL Server table with the results from the feature class.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; pyodbc
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
fc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:\FGDB.gdb\featureclass'&lt;/SPAN&gt;
cnxn &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; pyodbc&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;connect&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'Driver={ODBC Driver 17 for SQL Server};'&lt;/SPAN&gt;
 &lt;SPAN class="string token"&gt;'Server=SQLServer;'&lt;/SPAN&gt;
 &lt;SPAN class="string token"&gt;'Database=Database;'&lt;/SPAN&gt;
 &lt;SPAN class="string token"&gt;'Trusted_connection=yes'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'FCID'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'GCAcc'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; curFC&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 curSQL&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;cnxn&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;cursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 curSQL&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;execute&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'UPDATE tabAddress SET Addr1_GCAcc = ? WHERE TableID = ?'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; curFC&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; curFC&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 curSQL&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;commit&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
curSQL&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;close&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FYI, I changed the feature class and SQL server names in the above code.&amp;nbsp; However, I was able to successfully read the SQL server table using the pyodbc connection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After I run the script, I get the following error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;Traceback &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;most recent call last&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 File &lt;SPAN class="string token"&gt;"C:\Users\myprofile\Desktop\testODBC\asdf.py"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; line &lt;SPAN class="number token"&gt;14&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;module&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;
 curSQL&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;execute&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'UPDATE tabAddress SET Addr1_GCAcc = ? WHERE TableID = ?'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; curFC&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; curFC&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
SystemError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; error &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; without exception set‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FYI, FCID is a long integer field and GCAcc is a string field.&amp;nbsp; Could the FCID field in the execute statement not be formatting correctly?&amp;nbsp; I checked with the SQL Server admin and I'm supposed to have update capabilities.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Lucas Murray&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:08:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-updating-sql-server-table-using-pyodbc/m-p/28229#M2150</guid>
      <dc:creator>LucasMurray2</dc:creator>
      <dc:date>2021-12-10T21:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Error Updating SQL Server Table using pyodbc</title>
      <link>https://community.esri.com/t5/python-questions/error-updating-sql-server-table-using-pyodbc/m-p/28230#M2151</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your code snippet, what do you think &lt;CODE&gt;curFC&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;&lt;/CODE&gt; and &lt;CODE&gt;curFC&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;&lt;/CODE&gt; are exactly?&amp;nbsp; You have created the cursor but you haven't started iterating through it yet, so trying to index it will generate an error:&lt;CODE&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; fc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# path to feature class or table&lt;/SPAN&gt;
&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; cur &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;UpdateCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"*"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
Traceback &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;most recent call last&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp; File &lt;SPAN class="string token"&gt;"&amp;lt;stdin&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; line &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;module&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;
SystemError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; error &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; without exception set
&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; 
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:08:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-updating-sql-server-table-using-pyodbc/m-p/28230#M2151</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T21:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Error Updating SQL Server Table using pyodbc</title>
      <link>https://community.esri.com/t5/python-questions/error-updating-sql-server-table-using-pyodbc/m-p/28231#M2152</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for catching that.&amp;nbsp; Apparently I needed another cup of coffee that day.&amp;nbsp; Once I added the iteration,everything worked.&amp;nbsp; Thank you, Joshua.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jan 2019 17:46:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-updating-sql-server-table-using-pyodbc/m-p/28231#M2152</guid>
      <dc:creator>LucasMurray2</dc:creator>
      <dc:date>2019-01-23T17:46:25Z</dc:date>
    </item>
  </channel>
</rss>

