For our Enterprise Server Geodatabases, the ListUser function works well when using only one Geodatabase, but when looping through two or more Geodatabases is where I need some assistance.
My Script Error: ValueError: Not a valid SDE workspace.
import arcpy
#Local Variables: I need to loop through two or More Enterprise Server Geodatabases
fc="Arden@gsw_sde.sde", "CowanHeights@gsw_sde.sde"
arcpy.env.workspace = "Database Connections/fc"
workspace = arcpy.env.workspace
# get a list of connected users.
userList = arcpy.ListUsers("Database Connections/fc")
for user in users:
print("Username: {0}, Connected at: {1}".format(user.Name, user.ConnectionTime))
Solved! Go to Solution.
Looks like I missed a paren, it should be updated now.
Does looping through the connection list work?
workspaces = ["dbconn1.sde", "dbconn2.sde"] for sde in workspaces: arcpy.env.workspace = sde userList = arcpy.ListUsers(sde) for user in userList: print("Username: {0}, Connected at: {1}".format(user.Name, user.ConnectionTime))
Hi Christian-Thanks for you help on this. I'm getting a very Strange Syntax Error just below the print Command. Any thoughts?
workspaces = ["Arden.sde", "BayPoint.sde"]
for sde in workspaces:
arcpy.env.workspace = sde
userList = arcpy.ListUsers(sde)
for user in userList:
print("Username: {0}, Connected at: {1}".format(user.Name, user.ConnectionTime)
Looks like I missed a paren, it should be updated now.
Thanks Christain, this is what I finally ended up with and it worked. Can you please tell me about the Forward slash in the workspace and what this operator is doing? its not division
Thanks Once again,
Larry
workspaces = ["Database Connections/Arden@gsw_sde.sde", "Database Connections/BayPoint@gws_.sde.sde"]
for sde in workspaces:
arcpy.env.workspace = sde
userList = arcpy.ListUsers(sde)
for user in userList:
print("Username: {0}, Connected at: {1}".format(user.Name, user.ConnectionTime))
The forward slash represents a path separator. There are many ways to write these paths including raw strings: r'path\folder', double-backslashes: 'path\\folder', or forward slashes 'path/folder'
This is because a single backward slash can be interpreted as an escape character. Below is a helpful blog in understanding this Python issue.
Gotcha — backslashes in Windows filenames | Python Conquers The Universe