[GIS] Unable to connect to “Database Connections/.sde” from python

arcgis-10.3arcgis-desktoparcgis-serverarcpy

I just upgraded to 10.3.1 and now I am having issues running my administrative tasks set with Python scripts.

I am unable to use the string "Database Connections/some.sde", i.e:

arcpy.ListUsers("Database Connections/some.sde) Returns the following error:

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
userList = arcpy.ListUsers("Database Connections/some.sde")
File "C:\Program Files\ArcGIS\Server\ArcPy\arcpy\__init__.py", line 1058, in ListUsers
return utils.listofnamedtuples(gp.listUsers(sde_workspace), 'user')
File "C:\Program Files\ArcGIS\Server\ArcPy\arcpy\geoprocessing\_base.py", line 504, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
TypeError: Could not open SDE workspace.

I can use the full path string for some tasks like ListUsers, AcceptConnections,etc., but not others like reconcile and post, e.g.:

"C:\Users\%username%\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\some.sde"

Fails without throwing error at: arcpy.ReconcileVersions_management("C:\Users\%username%\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\some.sde","ALL_VERSIONS","DBO.QC","DBO.Chris;DBO.Joe","LOCK_ACQUIRED","NO_ABORT","BY_OBJECT","FAVOR_EDIT_VERSION","POST","KEEP_VERSION","#")

The full script is here, which worked great prior to 10.3 upgrade: reconcile and post script

In ArcCatalog I have created these database connections, they work fine, I can browse in Catolog, and the .sde files exist in my AppData/Roaming/ESRI subdirectory. I have tried copying all my old connection strings from the 10.2 into my roaming profile. Is there some environmental variable that needs to be repaired? Do I need to re-install Server and Desktop on this machine?

Question: How can I repair my "Database Connections" to run Python scripts

Best Answer

Use full paths in scripts.

As far as python failing on opening the workspace, you may just be encountering a python format issue with the escape character. It is discussed on this nice blog

to illustrate:

>>> str = "C:\folder\file"
>>> str
'C:\x0colder\x0cile' <--Path being passed to arcpy (Bad)

>>> str = "C:\\folder\\file"
>>> str
'C:\\folder\\file'   <-- Good

>>> str = r"C:\folder\file"
>>> str
'C:\\folder\\file'   <-- Also Good
Related Question