<?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: Python GPService SDE Connection in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742225#M24396</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you find a solution to this?&amp;nbsp; I am having the same issue.&amp;nbsp; I believe it is permissions wiht ArcGIS Server, but I'm not sure where to make the changes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 21 Jul 2014 13:46:36 GMT</pubDate>
    <dc:creator>KevinSadrak</dc:creator>
    <dc:date>2014-07-21T13:46:36Z</dc:date>
    <item>
      <title>Python GPService SDE Connection</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742223#M24394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to publish a GPService from a python script. I am having with the service connecting to SDE. I was having trouble so I added the Test Connection section to see what path was being used. It seems like it is not getting the connection info from the SDE file. The script runs fine in ArcMap and I have the SDE file in the same location on the server as it is my dev machine. Any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"Error executing tool.: C:\arcgisserver\directories\arcgissystem\arcgisinput\GPTools\WildfireUpload.GPServer\extracted\v101\\ArcSDE.dbo.WILDFIREPERIM Table does not exist "&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy, os, zipfile
from arcpy import env

#Setting the env workspace to be an SDE geodatabase
ws = env.workspace = "D:\\agsResources\\DataStoreSDEs\\GIS01(TEST Server).sde"
#Test Connection
if arcpy.Exists(ws + "\\ArcSDE.dbo.WILDFIREPERIM") == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Table does not exist")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(ws + "\\ArcSDE.dbo.WILDFIREPERIM Table does not exist")
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Table Exists")

infile = arcpy.GetParameterAsText(0)
#startdate = arcpy.GetParameterAsText(1)
outpath, outfileext = os.path.splitext(infile)
filename = outpath.split('\\')[-1]
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # unzip file
&amp;nbsp;&amp;nbsp;&amp;nbsp; fireZip = zipfile.ZipFile(infile, 'r')
&amp;nbsp;&amp;nbsp;&amp;nbsp; fireZip.extractall(outpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fireZip.close()
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.SetParameterAsText(1,outpath + "\\" + filename + ".shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; shpPath = outpath + "\\" + filename + ".shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Finished unzipping file.")

# Local variables:
&amp;nbsp;&amp;nbsp;&amp;nbsp; WildFire_Table_Target = ws + "\\ArcSDE.dbo.WILDFIREPERIM"
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create FieldMappings object and load the target dataset
#
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldmappings = arcpy.FieldMappings()
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldmappings.addTable(WildFire_Table_Target)

&amp;nbsp;&amp;nbsp;&amp;nbsp; inputfields = [field.name for field in arcpy.ListFields(shpPath) if not field.required]
&amp;nbsp;&amp;nbsp;&amp;nbsp; for inputfield in inputfields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Iterate through each FieldMap in the FieldMappings
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(fieldmappings.fieldCount):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldmap = fieldmappings.getFieldMap(i)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage(fieldmap.getInputFieldName(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If the field name from the target dataset matches to a validated input field name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fieldmap.getInputFieldName(0) == inputfield.replace("", ""):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add the input field to the FieldMap and replace the old FieldMap with the new
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldmap.addInputField(shpPath, inputfield)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldmappings.replaceFieldMap(i, fieldmap)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Process: Append
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Append_management(shpPath, WildFire_Table_Target, "NO_TEST", fieldmappings)

except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(e.message)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 12:45:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742223#M24394</guid>
      <dc:creator>BrianLeroux</dc:creator>
      <dc:date>2013-06-07T12:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Python GPService SDE Connection</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742224#M24395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So I stopped trying to use the workspace and I am just setting a variable with the path. This now shows the table exists.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;WildFire_Table_Target = r'D:\agsResources\DataStoreSDEs\HOCCSQLAH01_AHREPORT(TEST Server).sde\ArcSDE.dbo.WILDFIREPERIM'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However when trying to add the table to fieldmapping I get an error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldmappings.addTable(WildFire_Table_Target)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error executing tool.: FieldMappings: Error in adding table to field mappings Failed to execute (ImportWildfirePerim). Failed to execute (ImportWildfirePerim).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Doesn't make sense to me as it has no issues with the filed mapping in ArcMap.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 14:51:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742224#M24395</guid>
      <dc:creator>BrianLeroux</dc:creator>
      <dc:date>2013-06-07T14:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python GPService SDE Connection</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742225#M24396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you find a solution to this?&amp;nbsp; I am having the same issue.&amp;nbsp; I believe it is permissions wiht ArcGIS Server, but I'm not sure where to make the changes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2014 13:46:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742225#M24396</guid>
      <dc:creator>KevinSadrak</dc:creator>
      <dc:date>2014-07-21T13:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python GPService SDE Connection</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742226#M24397</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kevin-&lt;/P&gt;&lt;P&gt;I did get this to work but it was a while ago so I am having difficulty remembering everything i did to get this working. For the connection I had to use the following line to get this to work. You should also not that I use windows authentication and my gis server account needed write access to the SQL table that i was updating.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Local variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WildFire_Table_Target = "Database Connections\\GEOSQL01_ArcSDE(PROD Server).sde\\ArcSDE.dbo.WILDFIREPERIM"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2014 14:11:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742226#M24397</guid>
      <dc:creator>BrianLeroux</dc:creator>
      <dc:date>2014-07-21T14:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python GPService SDE Connection</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742227#M24398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt;Brian, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt;Thanks for the reply.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt;In order for your code to work, you had to put the .SDE in the&lt;BR /&gt;Database Connections, that is interesting.&amp;nbsp; I am creating a new .sde in my&lt;BR /&gt;script that will allow for version changes, I suppose I could try and move the&lt;BR /&gt;generated .sde to the Database Connections folder and see if that works.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt;I’ll post my findings!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt;-Kevin&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2014 14:21:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742227#M24398</guid>
      <dc:creator>KevinSadrak</dc:creator>
      <dc:date>2014-07-21T14:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python GPService SDE Connection</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742228#M24399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;and?&amp;nbsp; never posted your findings...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Jul 2015 21:45:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742228#M24399</guid>
      <dc:creator>MichaelRobb</dc:creator>
      <dc:date>2015-07-20T21:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Python GPService SDE Connection</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742229#M24400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is an update on my end. I ended up having success placing the sde connection file in the same directory as the script and then referencing that with a system path variable. Here is a sample. This has been the most consistent method for me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Get script path&lt;/P&gt;&lt;P&gt;script_path = sys.path[0]&lt;/P&gt;&lt;P&gt;#Path to SDE using new script path variable&lt;/P&gt;&lt;P&gt;sdeconn = os.path.join(script_path, "SQLDB.sde")&lt;/P&gt;&lt;P&gt;#Path to feature class&lt;/P&gt;&lt;P&gt;polfc = os.path.join(sdeconn, 'ArcSDE.dbo.MyData)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2015 12:21:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-gpservice-sde-connection/m-p/742229#M24400</guid>
      <dc:creator>BrianLeroux</dc:creator>
      <dc:date>2015-07-21T12:21:36Z</dc:date>
    </item>
  </channel>
</rss>

