Using the ListUser function, cannot loop through Two or more Server Geodatabases

2577
5
Jump to solution
06-09-2016 09:54 AM
LarryAdgate
Occasional Contributor

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))

0 Kudos
1 Solution

Accepted Solutions
ChristianWells
Esri Contributor

Looks like I missed a paren, it should be updated now.

View solution in original post

0 Kudos
5 Replies
ChristianWells
Esri Contributor

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))
LarryAdgate
Occasional Contributor

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)

0 Kudos
ChristianWells
Esri Contributor

Looks like I missed a paren, it should be updated now.

0 Kudos
LarryAdgate
Occasional Contributor

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))

0 Kudos
ChristianWells
Esri Contributor

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