Select to view content in your preferred language

List Fields and Associated Domains--gets stuck on one table, why?

6135
6
Jump to solution
06-14-2012 09:59 AM
847396730
Frequent Contributor
Hello!  This script combs the SDE's feature classes and tables and reports back which fields have domains applied and which domains they are.  It works beautifully, returning 553 records, until it hits a mystery table which our DBA created, called "DBASERVICE.TOAD_PLAN_TABLE."  I don't know what causes the error (see below the script).  I thought first that maybe the table had no fields, but SQLDev shows that it does--fields, but no data.  I need either to fix the issue, or write error-handling that will skip this table so that it will move on with the rest of the items in the SDE.  I don't know how to do either, so I'm hoping someone out there does!  Thanks!

HERE'S THE SCRIPT:
import arcpy
#Set workspace environment to geodatabase
arcpy.env.workspace = r"Database Connections\PROD_fakesrv1.SDE.sde"

#Get list of feature classes in geodatabase
FCs = arcpy.ListFeatureClasses()

#Loop through feature classes in list
for FC in FCs:

        #List fields in feature class
        fields = arcpy.ListFields(FC)

        #Loop through fields
        for field in fields:

            #Check if field has domain
            if field.domain != "":

                #Print feature class, field, domain name
                print FC, ",", field.name, ",", field.domain
               
#Get list of tables in geodatabase
TBs = arcpy.ListTables()

#Loop through tables in list
for TB in TBs:

        #List tables in feature dataset
        fields = arcpy.ListFields(TB)

        #Loop through fields
        for field in fields:

            #Check if field has domain
            if field.domain != "":

                #Print table, field, domain name
                print TB, ",", field.name, ",", field.domain

HERE'S THE ERROR:
Traceback (most recent call last):
  File "U:\SDE_Domains\WhichDomainsAreInUseHereSDE.py", line 30, in <module>
    fields = arcpy.ListFields(TB)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 787, in ListFields
    return gp.listFields(*args)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 342, in listFields
    self._gp.ListFields(*gp_fixargs(args)))
IOError: DBASERVICE.TOAD_PLAN_TABLE
>>>
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
847396730
Frequent Contributor
I skipped the offending tables with "continue:"

import arcpy, os #Set workspace environment to geodatabase arcpy.env.workspace = r"Database Connections\PROD_fakesrv1.SDE.sde"  #Get list of tables in geodatabase TBs = arcpy.ListTables()  #Loop through tables in list for TB in TBs:                  if TB == "DBASERVICE.TOAD_PLAN_TABLE":                       continue                  if TB == "TSMSYS.SRS$":                       continue                                      if TB == "NDOT.VW_CDS":                       continue                                  #List tables in feature dataset                 fields = arcpy.ListFields(TB)                  #Loop through fields                 for field in fields:                               #Check if field has domain                                        if field.domain != "":                      #Print table, field, domain name                         print TB, ",", field.name, ",", field.domain

View solution in original post

0 Kudos
6 Replies
ThaiTruong
Deactivated User
Hi there,

You might have to double check your for loop to see it it's missing an indented block.  Please re-post your python code with
 tags.

See this threadon how to post Python scripts!
0 Kudos
847396730
Frequent Contributor
Thanks for the input; here's the code (now with indents!) and the error.  Also--the script does return results; it just gets stuck on that one table.

import arcpy
#Set workspace environment to geodatabase
arcpy.env.workspace = r"Database Connections\PROD_fakesrv1.SDE.sde"

#Get list of feature classes in geodatabase
FCs = arcpy.ListFeatureClasses()

#Loop through feature classes in list
for FC in FCs:

        #List fields in feature class
        fields = arcpy.ListFields(FC)

        #Loop through fields
        for field in fields:

            #Check if field has domain
            if field.domain != "":

                #Print feature class, field, domain name
                print FC, ",", field.name, ",", field.domain
                
#Get list of tables in geodatabase
TBs = arcpy.ListTables()

#Loop through tables in list
for TB in TBs:

        #List tables in feature dataset
        fields = arcpy.ListFields(TB)

        #Loop through fields
        for field in fields:

            #Check if field has domain
            if field.domain != "":

                #Print table, field, domain name
                print TB, ",", field.name, ",", field.domain




ERROR:
Traceback (most recent call last):
  File "U:\SDE_Domains\WhichDomainsAreInUseHereSDE.py", line 30, in <module>
    fields = arcpy.ListFields(TB)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 787, in ListFields
    return gp.listFields(*args)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 342, in listFields
    self._gp.ListFields(*gp_fixargs(args)))
IOError: DBASERVICE.TOAD_PLAN_TABLE
0 Kudos
ThaiTruong
Deactivated User
Yep, I don't see anything wrong with your script.  For some reasons, I think your script cannot open/read that table.
If the table is empty, try to delete and re-create that table and its domain(s) again.
0 Kudos
847396730
Frequent Contributor
I think it's the table, too.  The table has fields, but no content.  I can neither delete nor recreate it, as it was made by a DBA whose "stuff" I'm not permitted to modify.  Thanks for looking!
0 Kudos
847396730
Frequent Contributor
How can I tell the script to "skip" the offending table and continue on with the remaining tables?
0 Kudos
847396730
Frequent Contributor
I skipped the offending tables with "continue:"

import arcpy, os #Set workspace environment to geodatabase arcpy.env.workspace = r"Database Connections\PROD_fakesrv1.SDE.sde"  #Get list of tables in geodatabase TBs = arcpy.ListTables()  #Loop through tables in list for TB in TBs:                  if TB == "DBASERVICE.TOAD_PLAN_TABLE":                       continue                  if TB == "TSMSYS.SRS$":                       continue                                      if TB == "NDOT.VW_CDS":                       continue                                  #List tables in feature dataset                 fields = arcpy.ListFields(TB)                  #Loop through fields                 for field in fields:                               #Check if field has domain                                        if field.domain != "":                      #Print table, field, domain name                         print TB, ",", field.name, ",", field.domain
0 Kudos