replacedata source error

1568
1
03-05-2012 03:18 AM
MichaelHarrop
New Contributor II
Hi,
I'm trying to update the data source of a layer in a mcd using arcpy, i can get this to work when updating to a fgb but not to SDE, is there an obvious error in the oce

import arcpy
mxd = arcpy.mapping.MapDocument(r"H:\MyDocuments\ArcGIS\Untitled.mxd")
sdepath = r"Z:\webapp\mapservices\Maps\connection-files\DEV\GISCO-DEV-direct-gisco.sde"
for lyr in arcpy.mapping.ListBrokenDataSources(mxd):
    if lyr.supports("DATASOURCE"):
        if lyr.dataSource == r"H:\MyDocuments\ArcGIS\Default.gdb\Export_Output":
            lyr.replaceDataSource(sdepath, "SDE_WORKSPACE", r"GISCOVIEW.STAT_LIFEXF_NUTS2_2006_8_01M")
            lyr.name = "LifeEX"
mxd.saveACopy(r"H:\MyDocuments\ArcGIS\Untitled1.mxd")

The error is Runtime error <type 'exceptions.ValueError'>: Layer: Unexpected error

Thanks
0 Kudos
1 Reply
JeffBarrette
Esri Regular Contributor
Michael,

A few questions:
1) What RDBMS are you going to?
2) Does your new SDE connection have user\password saved with it?
3) Is the connection a user account or an owner account?
4) If you were to manually add the layer from SDE into a map document, would its lyr.datasetName match the name you specified?
5) Do you get different results if you set validate=False

Jeff
0 Kudos