Select to view content in your preferred language

Error in Creation of multiple objects in an Enterprise Geodatabase

878
4
10-04-2022 11:04 PM
Cristian_Galindo
Frequent Contributor

1. Create a Enterprise geodatabase

2. Run the following code:

import arcpy

arcpy.env.workspace = r"C:\temp2\DataOwner.sde"
# arcpy.env.autoCommit = 5

for i in range(0, 100):
    arcpy.management.CreateDomain(arcpy.env.workspace, f"CG_Domain_{i}", f"CG_Domain_{i}", "TEXT", "CODED")
    print(f"CG_Domain_{i}")
    for j in range(0, 100):
        arcpy.management.AddCodedValueToDomain(arcpy.env.workspace, f"CG_Domain_{i}", f"CG_Domain_Code_{j}", f"CG_Domain_Code_{j}")
        print(f"    CG_Domain_Code_{j}")

 

3. the script never ends successfully, always in some point it crash

CG_Domain_0
CG_Domain_Code_0
CG_Domain_Code_1
CG_Domain_Code_2
CG_Domain_Code_3
CG_Domain_Code_4
Traceback (most recent call last):
File "C:/Users/svc_distripoint_nima/.PyCharmCE2019.1/config/scratches/scratch_1.py", line 10, in <module>
arcpy.management.AddCodedValueToDomain(arcpy.env.workspace, f"CG_Domain_{i}", f"CG_Domain_Code_{j}", f"CG_Domain_Code_{j}")
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 2652, in AddCodedValueToDomain
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 2649, in AddCodedValueToDomain
retval = convertArcObjectToPythonObject(gp.AddCodedValueToDomain_management(*gp_fixargs((in_workspace, domain_name, code, code_description), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000535: Workspace does not exist.
Failed to execute (AddCodedValueToDomain).

Some of the domains were created, but it keep returning error,

 

I want to check if this is related with the database, i can run a profiler (SQL Server profiler), but the databases are not my strongest skill. What should i look in that profiler, I mean which counters should i set ?

Is there a known reason for this behavior?

[EDIT 1]:  following the documentation I decided to use the following 2 statements right after import of the arcpy module:

 

arcpy.env.autoCommit = 100
arcpy.SetLogHistory(False)

The result is the same.

0 Kudos
4 Replies
by Anonymous User
Not applicable

The error is saying that the workspace (Dataowner.sde) does not exist, which is weird behavior. Maybe it is hitting the max allowed connections at that point and the script gets killed?

There are alternative ways that you can do this, like TableToDomain if you have a lot of values to add. It might be a better option and quicker than doing one by one.

 

0 Kudos
Cristian_Galindo
Frequent Contributor

@Anonymous User thanks for your answer. can you lead me where can I see the max allowed connections? currently I know for a fact that I am the only one connected to the geodatabase.

Currently this issue happens to me when I am creating a geodatabase with a big schema that involves Tables, FeatureClasses, relationships, views, domains. the error happens in different parts of the execution. the proposed script above was a simple way to reproduce the behavior.

The TableToDomain tool is not an option, because I need to create the table and insert the data therefore it will create more calls to the database.

The idea behind this is to have an script that allows me to create a geodatabase.

0 Kudos
by Anonymous User
Not applicable

I don't know what flavor of database you are using, but a quick google search can point you to where you can set it. By connections, I mean that it is not releasing the locks from the previous operation before starting on the new.  It is odd that randomly it will say that the workspace cannot be found..

The TableToDomain can accept a table that is created and held in memory, so you could dynamically create the values without creating/saving the table to the database. This link below has an example, or you can create it in a csv and to do a table to table before passing it to the TableToDomain.

https://community.esri.com/t5/python-questions/add-coded-values-to-a-domain-from-a-features/td-p/127... 

Cristian_Galindo
Frequent Contributor

@Anonymous User Thanks again, this will help me to improve the current script, but I will go in the direction of the locks, because this errors not only happens with the creation of domains.

0 Kudos