Select to view content in your preferred language

Workspace describe.connectionProperties vs Layer.connectionProperties

341
1
Jump to solution
08-01-2022 02:31 PM
YinghongLi1
Frequent Contributor

I am confused by these two.  They may contain similar information but the ways to get the values out of them seem a bit different.

The Pro help states clearly:  Layer.connectionProperties is a layer's data source connection information as a Python dictionary.   Workspace describe.connectionProperties is a property set

I do not understand the difference of getting values out of them.  See sample code below.  Thanks. 

Here is the sample code to get layer connection properties:

conn_prop=layer.connectionProperties  

conn_info=conn_prop['connection_info']  #db_connection_properties']  

instance =conn_info['db_connection_properties']  #giswpddev

print(conn_info)

version=conn_info['version']

print (version)

print(instance)

Print(conn_prop)

Here is the sample code workspace describe connection properties:

desc=arcpy.Describe(workspace_sde)

print("%-24s %s" % ("Connection String:", desc.connectionString))

print("%-24s %s" % ("WorkspaceFactoryProgID:", desc.workspaceFactoryProgID))

print("%-24s %s" % ("Workspace Type:", desc.workspaceType))

cp = desc.connectionProperties

print(cp)   #this return an empty object

print("\nDatabase Connection Properties:")

print("%-12s %s" % ("  Server:", cp.server))

print("%-12s %s" % ("  Instance:", cp.instance))

#print("%-12s %s" % ("  Database:", cp.database))

print("%-12s %s" % ("  User:", cp.user))

print("%-12s %s" % ("  Version:", cp.version))

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

I think you do understand the different ways of getting information out of them because you have provided sample code demonstrating how to extract connection properties from both.  If your confusion is why these are different, I think the answer is because they were developed at different times, using different parts of Pro's underlying code, and there is no requirement that connection property information has to be returned in a single format.

View solution in original post

1 Reply
JoshuaBixby
MVP Esteemed Contributor

I think you do understand the different ways of getting information out of them because you have provided sample code demonstrating how to extract connection properties from both.  If your confusion is why these are different, I think the answer is because they were developed at different times, using different parts of Pro's underlying code, and there is no requirement that connection property information has to be returned in a single format.