0

I am working with ArcGIS Pro 2.1 and Python 3.6.2. and I am writing a script that involves the arcpy.ListUsers() function and whenever I run the code I receive the following error:

arcpy.ListUsers() error

The SDE workspace can be accessed I have tried the arcpy.ListFeatureClasses() and the function did not fail or receive an error message; I am also able to open the connection in Catalog.

What can I do to get past this issue (this function is necessary for my script, so it cannot be removed)?

*Note: The arcpy.ListUsers() function fails whether it is ran in the script or on its own.

Here is the code that I have so far:

# import system modules
print("Importing system modules...")
import arcpy, os, shutil

# crete a temp folder to store a database connection
print("Checking for the temp directory...")
directory = r"P:\Python"
if not os.path.exists(directory):
    os.makedirs(directory)

# check for CGF database connection
print("Creating the database connection...")
if not arcpy.Exists(r"P:\Python\CGF_temp.sde"):
    # if non existent, create a connection
    arcpy.CreateDatabaseConnection_management(directory, "CGF_temp.sde", "SQL_SERVER", "###", "DATABASE_AUTH", "###",
                                          "###", "SAVE_USERNAME", "CGF")

# set workspace environments
# workspace must be a connection file to an ADMIN (sde) connection
print("Setting the workspace environments...")
arcpy.env.workspace = r"P:\Python\CGF_temp.sde"
arcpy.env.overwriteOutput = True
workspace = arcpy.env.workspace

# obtaining a list of connected users
print("Obtaining a list of connected users...")
users = arcpy.ListUsers("CGF_temp.sde")
print(users)
  • Could you perhaps post some of the code you have written? Maybe just up to where it fails? Have you tried running the script in ArcMap desktop and not Pro? I am still new to Pro, but have seen minor differences in the was things are called for the Pro licenses. – Keagan Allan Apr 4 '18 at 16:40
  • I added in the script that I have so far. I have not tried running the script in Desktop as I have uninstalled it from my computer to get rid of the confusion with Python versions. I am new to Pro as well and have noticed a few minor differences in the syntax. – Rosemary Apr 4 '18 at 17:05
  • Have you tried using the full path to the SDE connection file? – Keagan Allan Apr 4 '18 at 17:09
  • I have tried using the full path, I have also tried using "Database Connection/CGF_temp.sde" and I have tried using 'workspace'. I end up getting the same error every time. – Rosemary Apr 4 '18 at 17:21
  • Have you tried Alex's answer below? – Keagan Allan Apr 4 '18 at 17:32
1

Your problem is that you are setting up the arcpy.env.workspace to be the path to the .sde connection file. When you run the ListUsers, it cannot find the .sde file inside the .sde file.

Instead of

arcpy.env.workspace = r"C:\Temp\CGF_temp.sde"

Set it to be

arcpy.env.workspace = r"C:\Temp"

  • I just changed the code to match your suggestion and I still receive the same error. With the ListUsers() function I am not calling on the workspace, I am only calling the .sde, so it should not affect the function finding the .sde. Should it? – Rosemary Apr 4 '18 at 17:44
  • According to the help it looks like it'll work with and without a arcpy.env.workspace set. Not sure what happens if you set both. But try each scenario: workspace set and nothing into ListUsers and viceversa. – KHibma Apr 5 '18 at 0:00
  • @KHibma, you are right, it can work with and without setting the arcpy.env.workspace. However, in the question body, the code was to set up the arcpy.env.workspace to be inside the .sde file and ListUsers has received the .sde path again. If you set the workspace to be a path to an .sde file and then call ListUsers() without passing the path again, you'd get TypeError: ListUsers() missing 1 required positional argument: 'sde_workspace'. So you anyway need to pass either the full path or just the name of .sde file if you have already set the workspace folder. – Alex Tereshenkov Apr 5 '18 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.