I have encountered something kind of odd and I'm not sure what's causing it. I have published a geoprocessing service and it's duplicating the SDE connection file during publishing. The code is very simple, all it's doing is checking that a database connection can be made and then unzipping the uploaded file. The service works, but I'd like to understand why it's duplicating the SDE connection file.
The python code:
import arcpy, zipfile
db_con = r'Database Connections\HbMonitoringTest_nbcidb_HabitatTestWriter.sde'
arcpy.AddMessage(db_con)
if arcpy.Exists(db_con):
arcpy.AddMessage("your db connection worked")
else:
arcpy.AddMessage("your db connection sucks")
try:
myZipFile = arcpy.GetParameterAsText(0)
arcpy.AddMessage(myZipFile)
scratch = arcpy.env.scratchFolder
arcpy.AddMessage(scratch)
zip_ref = zipfile.ZipFile(myZipFile, 'r')
zip_ref.extractall(scratch)
zip_ref.close()
arcpy.AddMessage("success")
except:
arcpy.AddMessage("fail")
When I publish this as a geoprocessing service it does this in the /extracted/v101 directory:
Other info: When I use the service via javascript API, it uses the duplicate database connection (HbMonitoringTest_nbcidb_HabitatTestWriter1.sde). When I run the service in Desktop, it uses the catalog connection which is to be expected (this is the connection without the 1 on the end). This database is registered with the server under the same name (HbMonitoringTest_nbcidb_HabitatTestWriter). The server and publishing machine are two different machines. Server settings do not allow data to be copied to the server. ArcGIS Server 10.4.1, ArcGIS Desktop 10.6.