I am working on a python script that loops through each layer in a map document and prints out the database connection details for the particular layer.
I have some layers on the map which require a user/password for the layer to load.
What is the best way to get access to the connection details e.g. Instance, Database platform etc of a layer that requires a password.
I can get access to the datasource using layer.dataSource without a password but when I try and use arcpy.describe(layer.dataSource)
I am prompted with the dialog to enter the username/password.
I would like to get the highlighted information before the dialog appears.
enter image description here
Does anyone know the best way to do this?
-
It is not possible to retrieve the password of an enterprise geodatabase workspace.Vince– Vince2017年01月31日 12:43:15 +00:00Commented Jan 31, 2017 at 12:43
-
@Vince I do not want to retrieve the password, but the database platform and instance, as per the image shown.MapMan– MapMan2017年01月31日 12:44:58 +00:00Commented Jan 31, 2017 at 12:44
-
@Vince It's possible, since ArcGIS's software does it. They just don't expose an interface for doing so. Very different things.jpmc26– jpmc262018年12月05日 19:46:20 +00:00Commented Dec 5, 2018 at 19:46
-
@jpmc26 I stand by my phrasing. The password cannot be retrieved. It can be decrypted and used, but it cannot be returned (which conforms to standard security practice). Put another way, password is a write-only property -- there is no getter.Vince– Vince2018年12月05日 23:08:02 +00:00Commented Dec 5, 2018 at 23:08
-
@Vince I'm quite certain that an attacker possessing the MXD could figure out how to retrieve it, since if it even is encrypted, the decryption key must be distributed with every version of ArcGIS capable of retrieving it. "It is not possible" suggests a level of security that simply does not exist in this instance.jpmc26– jpmc262018年12月05日 23:14:08 +00:00Commented Dec 5, 2018 at 23:14
2 Answers 2
According to the documentation, you should be able to get the connection string from describing the workspace:
arcpy.Describe(r'Database Connections\SomeDB.sde').connectionString
However, this does not work for me (bug?). One thing you can do is get at a feature class your SDE and get the serviceProperties
. This is not the full connection string, but you can use those properties to create the connection string.
fc = r'Database Connections\SomeDB.sde\SomeDB.DBO.SomeFc'
lyr = arcpy.mapping.Layer(fc)
print lyr.serviceProperties # this is a dict of connection properties
-
i get the following
The attribute 'serviceProperties' is not supported on this instance of Layer.
when i tryprint layer.serviceProperties
I think this is because the password is requiredMapMan– MapMan2017年01月31日 14:55:39 +00:00Commented Jan 31, 2017 at 14:55 -
1The connection string is empty if the usename and password are not saved. Only the individual elements of the connectionProperties child of the workspace description are available. I think I remember getting prompted for connection parameters during a ListWorkspaces of "Database Connections", so a Describe on the source workspace may challenge for usernam/password.Vince– Vince2017年02月01日 04:14:07 +00:00Commented Feb 1, 2017 at 4:14
This is an old post but there is a support doc from ESRI that I believe solves this question adequately