Select to view content in your preferred language

Problem updating tableview broken data sources.

6867
26
03-21-2012 11:13 AM
MathewCoyle
Honored Contributor
I have several mxds with broken data sources to SDE after a database move. I am running a script to update the broken data sources and keep getting an error on broken links to table views. All other layers update correctly.

Here is the error I get
Runtime error <type 'exceptions.ValueError'>: StandaloneTableObject: Unexpected error


Here's the relevant code where I am getting the error.
brokenlist = arcpy.mapping.ListBrokenDataSources(mxd)
for lyr in brokenlist:
    if ".sde" in lyr.dataSource:
        try:
            lyr.replaceDataSource(new_datasource, "SDE_WORKSPACE", lyr.name)


Has anyone encountered this or know a work around?

Edit: I've tried it with and without the lyr.name specified.
Tags (2)
0 Kudos
26 Replies
MichaelVolz
Esteemed Contributor

What version of ArcMap are you using?  I ran my script in ArcMap v10.2.0, so maybe ESRI has updated python so it can better handle broken tableview connections in v10.2.2 or v10.3.0.  As such, I would log an incident with ESRI.

I will probably be doing this same task, but my organization probably is about a year away from this migration from 10.2.0 to 10.3.1 or 10.4, depending upon when ESRI releases 10.4.

0 Kudos
lelaharrington
Regular Contributor

i am in 10.1 we are just now getting to 10.2.2

Thank you

Lela Harrington

0 Kudos
MichaelVolz
Esteemed Contributor

Have you thought about going to 10.3 or 10.3.1 (should be out shortly) instead of going to v10.2.2?  This item (plus others) might be better handled in this later version.

Do you have any .NET or C# programming experience?  You would probably be able to handle this scenario in this programming environment as it is more robust.

0 Kudos
lelaharrington
Regular Contributor

no we are in the process of upgrading our servers. we will probably not branch to the 10.3 or 10.4 for a couple more years we are about 2-3 years behind the curve on that. 

this is really a one time deal where i just want to get a list of broken data sources and bypass the broken table sources. the except in the script stops it from erroring but not getting the table sourcing stops the script from advancing as well. 

Thank you

Lela Harrington

0 Kudos
lelaharrington
Regular Contributor

how did you flag the broken tables into a log file?

0 Kudos
MichaelVolz
Esteemed Contributor

Lela:

I loop through the TableViews in the dataframe (frm) that has the focus in the mxd that has focus:

#Loop through standalone tables in the focus dataframe
                            for tab in arcpy.mapping.ListTableViews(mxd, "", frm):
                                print("The table name in table loop is " + tab.name)
                                print("The table's datasource is " + tab.dataSource)
                                print("The table's workspacePath is " + tab.workspacePath)

                                if tab.workspacePath.endswith(".sde"):
                                    cntTab += 1

                            if cntTab > 0:
                                del tab

I then printed out the cntTab to the log file that the script is writing to.  I did not have a significant number of TableViews, so manually fixing the ones I found was efficient enough for me.  If you have a significant number of TableViews then the manual fix will take much longer (but at least you know where these tables are in your mxds).

0 Kudos
lelaharrington
Regular Contributor

That is perfect

Thank you

Lela Harrington

0 Kudos