0

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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 31, 2017 at 12:30
5
  • It is not possible to retrieve the password of an enterprise geodatabase workspace. Commented 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. Commented 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. Commented 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. Commented 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. Commented Dec 5, 2018 at 23:14

2 Answers 2

1

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
answered Jan 31, 2017 at 14:23
2
  • i get the following The attribute 'serviceProperties' is not supported on this instance of Layer.when i try print layer.serviceProperties I think this is because the password is required Commented Jan 31, 2017 at 14:55
  • 1
    The 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. Commented Feb 1, 2017 at 4:14
0

This is an old post but there is a support doc from ESRI that I believe solves this question adequately

https://support.esri.com/en/technical-article/000011781

answered Apr 20, 2018 at 16:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.