I have an ArcGis Project with a single map that has a single layer whose source is in an Enterprise Geodatabase. I want to use arcpy to publish this map to my standalone ArcGis Server (version 10.9.1) as a Map Service with a Feature Service and I want the source data to be copied to the server when I publish the services.
If I use arcpy.mapping and an mxd file containing the same single layer, then I am able to publish a Map Service with a Feature Service to my standalone ArcGis Server and the source data is copied to the server as specified via the copy_data_to_server parameter of the arcpy.mapping.CreateMapSDDraft method. However, I do not want to use ArcGis Desktop an mxd files anymore, I want to use ArcGis Pro and mapx files instead.
I have a python script where I use arcpy.mp to open the ArcGisProject, get a reference to the map and then I call arcpy.sharing.CreateSharingDraft as follows, to get a MapServiceDraft object:
mapSd = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER", "MAP_SERVICE", "MyMapService", mapObj)
Then I set the following properties on the MapServiceDraft as follows:
mapSd.offline = False
mapSd.copyDataToServer = True
mapSd.targetServer = connection_file
Then I call mapSd.exportToSDDraft to create the sddraft file. I subsequently modify the sddraft file as shown in the "Publish a map service with a feature service" sample in the MapServiceDraft online documentation. Finally, I call arcpy.server.StageService to generate a service definition file based on my draft and I get the following error:
arcgisscripting.ExecuteError: ERROR 001272: \Analyzer errors were encountered ([{"code":"00231","message":"Layer's data source must be registered with the server","object":"MyLayer"}]).
The point of setting copyDataToServer is to trigger the arcpy infrastructure to copy the data from the layer's source, to the ArcGis Server because I do not want to register my data source with the server. The documentation for copyDataToServer on MapServiceDraft certainly suggests that setting this value to True will cause the source data to be copied to the server. But instead of that happening, I get an error suggesting that I have no choice but to register my source, which I do not want to do.
Note, that if I do not modify the sddraft file, such that only a Map Service is published without a corresponding Feature Service, then the publish is successful. This is relevant because it validates the rest of my script apart from the modification of the sddraft file to trigger the creation of a Feature Service along with the Map Service. But of course my goal is to publish a Map Service with a Feature Service as I have always done with ArcMap mxd files and arcpy.mapping.
Does copyDataToServer work?