issues updating data source via arcpy.mapping

2728
5
02-16-2011 10:32 AM
RobertoFigueroa
New Contributor III
Hi,
I am running the python script listed at the bottom of this message to update the data source of many layers included in one of my .mxd's.
Although the script loops though all layers in the map, the data source is only updated in the first 37 layers of more than 350 in the map.
All layers I am trying to point to are stored in SDE in a single SQL Server 2005 database.
After running the Pyhton script in ArcMap, I intermittently get an error message for my SDE connection saying that "Maximum number of connections to instance exceeded". Perhaps the "lyr.replaceDataSource " method tries to connect multiple times to SDE and runs out of connections.
Any assistance would be greatly appreciated.
Best regards
Roberto


<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.isFeatureLayer:
        wrkspcpath = r"C:\Documents and Settings\rfiguero\Application Data\ESRI\Desktop10.0\ArcCatalog\cmtni_emili_sde_SYSTEST.sde"
        old_dataname = lyr.datasetName
        new_dataname = old_dataname + '_1'
        lyr.replaceDataSource (wrkspcpath, "SDE_WORKSPACE", new_dataname)
        print wrkspcpath, new_dataname
0 Kudos
5 Replies
JeffBarrette
Esri Regular Contributor
We are aware of this issue and are working on a fix.  It won't be available for SP2.

In order to support some workflows we did not recycle SDE connections with each lyr iteration so lyr.replaceDataSources is creating a new SDE connection with each iteration.  The cache is cleared when the script stops running or sometimes when you delete the variable references.

Some workarounds are to:

1) Try deleting the lyr variable at the end of each loop.  This does not always work.
2) Increase the number of available SDE connections on your server.
3) Decrease the number of layers that are updated within a single loop/script.  One example may be that your script iterates through 25 layers at a time.  You could have one master script that calls each subscript.

Jeff
0 Kudos
RuthEmerick
New Contributor II
Jeff, is there any chance setting up direct connections to the SDE would help with this? I've run into the same problem as Roberto.
0 Kudos
JeffBarrette
Esri Regular Contributor
We can reproduce this issue an will hopefully be able to address it in the next service pack.

If you want to check its status, it is: NIM067157

Thanks,
Jeff
0 Kudos
JeffBarrette
Esri Regular Contributor
This issue has been fixed and will be available with SP3.

Thanks,
Jeff
0 Kudos
RuthEmerick
New Contributor II
This issue has been fixed and will be available with SP3.

Thanks,
Jeff


Woot! Thanks!
0 Kudos