<?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 insert into sql table from geoprocessing service in ArcGIS Enterprise Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-questions/insert-into-sql-table-from-geoprocessing-service/m-p/526819#M20398</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;I have a geoprocessing service that kicks off a python script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In that python script:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;make a map&lt;/LI&gt;&lt;LI&gt;take the map as a png file and insert it into a sql table&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Python script works fine on the server.&lt;/P&gt;&lt;P&gt;Python script works fine as a custom ArcTool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I create a geoprocessing service. It fails.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have stripped the code down to just the insert.&amp;nbsp; It appears I can insert into the sql table as long as I do not include the map.&amp;nbsp; but if I do, it does not work in the geoprocessing service. I thought it might be a pathname issue, so I tried putting the png in the same directory as the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code:&lt;/P&gt;&lt;P&gt;=============================================================================&lt;/P&gt;&lt;P&gt;import pypyodbc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rec_creation_userid = '1234'&lt;/P&gt;&lt;P&gt;wl_id = 99&lt;/P&gt;&lt;P&gt;mime_type = 'image/png'&lt;/P&gt;&lt;P&gt;map_file_name = '99.png'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# tried with pathname - does NOT work in gp service&lt;/P&gt;&lt;P&gt;well_location_map = 'C:\\pathname\\maps\\99.png'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# tried with null- does&amp;nbsp; work in gp service&lt;/P&gt;&lt;P&gt;well_location_map= ""&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# tried with no pathname - does NOT work in gp service&lt;/P&gt;&lt;P&gt;well_location_map = '99.png'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;parameters = rec_creation_userid, wl_id, mime_type, map_file_name, well_location_map&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cnxn = None;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cnxn = pypyodbc.connect('DRIVER={SQL Server Native Client 10.0};SERVER=myserver\\AAAA;DATABASE=database;UID=username;PWD=password')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cursor = cnxn.cursor()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#==== uses a stored procedure for the insert=======&lt;/P&gt;&lt;P&gt;sp = "set nocount on ; "&lt;/P&gt;&lt;P&gt;sp = sp + "DECLARE @return_value int; "&lt;/P&gt;&lt;P&gt;sp = sp + "DECLARE @new_serial_id int; "&lt;/P&gt;&lt;P&gt;sp = sp + "DECLARE @return_msg varchar(250); "&lt;/P&gt;&lt;P&gt;sp = sp + "exec&amp;nbsp;&amp;nbsp;&amp;nbsp; @return_value = dbo.wrd_wl_pend_map_attachment_insert @new_serial_id OUTPUT, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @return_msg OUTPUT, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @current_userid = ?, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @wl_id = ?, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @mime_type = ?, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @map_file_name = ? , \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @map_attachment = ?&amp;nbsp; "&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sp = sp + "select @return_value as return_value, @new_serial_id as new_serial_id, @return_msg as return_msg ; "&lt;/P&gt;&lt;P&gt;cursor.execute(sp, parameters)&lt;/P&gt;&lt;P&gt;row = cursor.fetchone()&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if (row[0] &amp;gt; 0):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; logfile.write("There was an error: " + str(row[0])&amp;nbsp; + "\n\n")&lt;/P&gt;&lt;P&gt;print row &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cursor.close()&lt;/P&gt;&lt;P&gt;cnxn.commit()&lt;/P&gt;&lt;P&gt;cnxn.close()&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Oct 2014 18:01:18 GMT</pubDate>
    <dc:creator>DorothyMortenson</dc:creator>
    <dc:date>2014-10-15T18:01:18Z</dc:date>
    <item>
      <title>insert into sql table from geoprocessing service</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/insert-into-sql-table-from-geoprocessing-service/m-p/526819#M20398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;I have a geoprocessing service that kicks off a python script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In that python script:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;make a map&lt;/LI&gt;&lt;LI&gt;take the map as a png file and insert it into a sql table&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Python script works fine on the server.&lt;/P&gt;&lt;P&gt;Python script works fine as a custom ArcTool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I create a geoprocessing service. It fails.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have stripped the code down to just the insert.&amp;nbsp; It appears I can insert into the sql table as long as I do not include the map.&amp;nbsp; but if I do, it does not work in the geoprocessing service. I thought it might be a pathname issue, so I tried putting the png in the same directory as the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code:&lt;/P&gt;&lt;P&gt;=============================================================================&lt;/P&gt;&lt;P&gt;import pypyodbc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rec_creation_userid = '1234'&lt;/P&gt;&lt;P&gt;wl_id = 99&lt;/P&gt;&lt;P&gt;mime_type = 'image/png'&lt;/P&gt;&lt;P&gt;map_file_name = '99.png'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# tried with pathname - does NOT work in gp service&lt;/P&gt;&lt;P&gt;well_location_map = 'C:\\pathname\\maps\\99.png'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# tried with null- does&amp;nbsp; work in gp service&lt;/P&gt;&lt;P&gt;well_location_map= ""&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# tried with no pathname - does NOT work in gp service&lt;/P&gt;&lt;P&gt;well_location_map = '99.png'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;parameters = rec_creation_userid, wl_id, mime_type, map_file_name, well_location_map&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cnxn = None;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cnxn = pypyodbc.connect('DRIVER={SQL Server Native Client 10.0};SERVER=myserver\\AAAA;DATABASE=database;UID=username;PWD=password')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cursor = cnxn.cursor()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#==== uses a stored procedure for the insert=======&lt;/P&gt;&lt;P&gt;sp = "set nocount on ; "&lt;/P&gt;&lt;P&gt;sp = sp + "DECLARE @return_value int; "&lt;/P&gt;&lt;P&gt;sp = sp + "DECLARE @new_serial_id int; "&lt;/P&gt;&lt;P&gt;sp = sp + "DECLARE @return_msg varchar(250); "&lt;/P&gt;&lt;P&gt;sp = sp + "exec&amp;nbsp;&amp;nbsp;&amp;nbsp; @return_value = dbo.wrd_wl_pend_map_attachment_insert @new_serial_id OUTPUT, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @return_msg OUTPUT, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @current_userid = ?, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @wl_id = ?, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @mime_type = ?, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @map_file_name = ? , \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @map_attachment = ?&amp;nbsp; "&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sp = sp + "select @return_value as return_value, @new_serial_id as new_serial_id, @return_msg as return_msg ; "&lt;/P&gt;&lt;P&gt;cursor.execute(sp, parameters)&lt;/P&gt;&lt;P&gt;row = cursor.fetchone()&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if (row[0] &amp;gt; 0):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; logfile.write("There was an error: " + str(row[0])&amp;nbsp; + "\n\n")&lt;/P&gt;&lt;P&gt;print row &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cursor.close()&lt;/P&gt;&lt;P&gt;cnxn.commit()&lt;/P&gt;&lt;P&gt;cnxn.close()&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 18:01:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/insert-into-sql-table-from-geoprocessing-service/m-p/526819#M20398</guid>
      <dc:creator>DorothyMortenson</dc:creator>
      <dc:date>2014-10-15T18:01:18Z</dc:date>
    </item>
  </channel>
</rss>

