Hello,
I'm working on a script to read all the SDE connections from my Pro project to check whether this datasource is registered with my Arcgis Server. If the datasource is not registered, I want to fix this by adding the connection to Arcgis Server.
This script should avoid copying the data to Arcgis Server from my Enterprise Geodatabase when I publish a mapservice from an Arcpy Script.
I found the following functions in the Python documentation:
https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.server.html#arcgis.gis.server.DataStoreManager.generate_connection_string
https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.server.html#arcgis.gis.server.DataStoreManager.add_database
However, my script gives an error when I run the generate_connection_string function on the datastoremanager object.
The datastoremanager object works fine when I list the datasources which are registered with Arcgis Server
I'm using Arcgis Pro 2.2.4 with arcgis python package 1.4.1 and Arcgis Enterprise 10.6.1
The following script gives the error creating the connectionwhen I run it from the Python console in Pro:
<SPAN class="keyword token">import</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis
<SPAN class="keyword token">import</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis<SPAN class="punctuation token">.</SPAN>server
gis <SPAN class="operator token">=</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis<SPAN class="punctuation token">.</SPAN>GIS<SPAN class="punctuation token">(</SPAN>url<SPAN class="operator token">=</SPAN><SPAN class="string token"><SPAN>'</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fesri.joelhempenius.nl%2Fportal%2F" target="_blank">https://esri.joelhempenius.nl/portal/</A><SPAN>'</SPAN></SPAN><SPAN class="punctuation token">,</SPAN> username<SPAN class="operator token">=</SPAN><SPAN class="string token">'portaladmin'</SPAN><SPAN class="punctuation token">,</SPAN>password<SPAN class="operator token">=</SPAN><SPAN class="string token">'fakepassword'</SPAN><SPAN class="punctuation token">)</SPAN>
server <SPAN class="operator token">=</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis<SPAN class="punctuation token">.</SPAN>server<SPAN class="punctuation token">.</SPAN>Server<SPAN class="punctuation token">(</SPAN>url<SPAN class="operator token">=</SPAN><SPAN class="string token"><SPAN>'</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fesri.joelhempenius.nl%2Fserver" target="_blank">https://esri.joelhempenius.nl/server</A><SPAN>'</SPAN></SPAN><SPAN class="punctuation token">,</SPAN> gis<SPAN class="operator token">=</SPAN>gis<SPAN class="punctuation token">)</SPAN>
datastoremanager <SPAN class="operator token">=</SPAN> server<SPAN class="punctuation token">.</SPAN>datastores
datastoremanager
<SPAN class="operator token"><</SPAN>DataStoreManager <SPAN class="keyword token">for</SPAN> https<SPAN class="punctuation token">:</SPAN><SPAN class="operator token">//</SPAN>esri<SPAN class="punctuation token">.</SPAN>joelhempenius<SPAN class="punctuation token">.</SPAN>nl<SPAN class="operator token">/</SPAN>server<SPAN class="operator token">/</SPAN>admin<SPAN class="operator token">/</SPAN>data<SPAN class="operator token">></SPAN>
datastoremanager<SPAN class="punctuation token">.</SPAN>list<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">[</SPAN><SPAN class="operator token"><</SPAN>Datastore title<SPAN class="punctuation token">:</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fesri.joelhempenius.nl%2Fserver%2Fadmin%2Fdata%2Fitems%2FenterpriseDatabases%2FAGSDataStore_ds_dxwu2ulk" target="_blank">https://esri.joelhempenius.nl/server/admin/data/items/enterpriseDatabases/AGSDataStore_ds_dxwu2ulk</A><SPAN>"</SPAN></SPAN> type<SPAN class="punctuation token">:</SPAN><SPAN class="string token">"egdb"</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token"><</SPAN>Datastore title<SPAN class="punctuation token">:</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fesri.joelhempenius.nl%2Fserver%2Fadmin%2Fdata%2Fitems%2FenterpriseDatabases%2Fov" target="_blank">https://esri.joelhempenius.nl/server/admin/data/items/enterpriseDatabases/ov</A><SPAN>"</SPAN></SPAN> type<SPAN class="punctuation token">:</SPAN><SPAN class="string token">"egdb"</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token"><</SPAN>Datastore title<SPAN class="punctuation token">:</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fesri.joelhempenius.nl%2Fserver%2Fadmin%2Fdata%2Fitems%2FenterpriseDatabases%2Fov_pro" target="_blank">https://esri.joelhempenius.nl/server/admin/data/items/enterpriseDatabases/ov_pro</A><SPAN>"</SPAN></SPAN> type<SPAN class="punctuation token">:</SPAN><SPAN class="string token">"egdb"</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token"><</SPAN>Datastore title<SPAN class="punctuation token">:</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fesri.joelhempenius.nl%2Fserver%2Fadmin%2Fdata%2Fitems%2FenterpriseDatabases%2Fsde_ov%40gis_t" target="_blank">https://esri.joelhempenius.nl/server/admin/data/items/enterpriseDatabases/sde_ov@gis_t</A><SPAN>"</SPAN></SPAN> type<SPAN class="punctuation token">:</SPAN><SPAN class="string token">"egdb"</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token"><</SPAN>Datastore title<SPAN class="punctuation token">:</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fesri.joelhempenius.nl%2Fserver%2Fadmin%2Fdata%2Fitems%2FnosqlDatabases%2FAGSDataStore_nosqldb_tcs_1hpjd8nn" target="_blank">https://esri.joelhempenius.nl/server/admin/data/items/nosqlDatabases/AGSDataStore_nosqldb_tcs_1hpjd8nn</A><SPAN>"</SPAN></SPAN> type<SPAN class="punctuation token">:</SPAN><SPAN class="string token">"nosql"</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">]</SPAN>
datastoremanager<SPAN class="punctuation token">.</SPAN>generate_connection_string<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'C:\SDE\sde_ov@gis_t.sde'</SPAN><SPAN class="punctuation token">)</SPAN>
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
File <SPAN class="string token">"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\admin\_data.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">315</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> generate_connection_string
<SPAN class="keyword token">if</SPAN> self<SPAN class="punctuation token">.</SPAN>_con<SPAN class="punctuation token">.</SPAN>portal_connection<SPAN class="punctuation token">:</SPAN>
AttributeError<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'_ArcGISConnection'</SPAN> object has no attribute <SPAN class="string token">'portal_connection'</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I also tried server = arcgis.gis.server.Server(url='https://esri.joelhempenius.nl/server/admin', gis=gis), but this gives me the same error.
Any ideas why I get this error?