replace datasource problem

2498
6
Jump to solution
09-02-2013 05:32 AM
JeroenWisse
New Contributor
Hi All,

I got a problem with changing multiple datasources in a mxd.

We are migrating from arcgis 9.3.1 to 10.1 and at the same time we are changing our sde structure.
In the old structure we are using a lot of feature datasets to group data.
In the new structure we remove the feature datasets. So basically all the data in the  "root".

When i run the below code it changes the datasources for all layers but only the first layer has it's dataset removed. Meaning only the first layer succeeds and the other layers show up as broken. If i then look at the datasource properties via arcmap it still shows the old feature dataset.

below the relevant code:
mxd = arcpy.mapping.MapDocument(r"KabelsenLeidingen.mxd")  for layer in arcpy.mapping.ListLayers(mxd):         newDBPath=""     newDBPath=findNewPath(layer.dataSource,layer.workspacePath)     if newDBPath!="not found":         layer.replaceDataSource(newDBconnection,"SDE_WORKSPACE",newDBPath,False)  mxd.save() 

the newDBPath variable is set via a function and is always correct.

When running the above code it only removes the dataset of the first layer. The replaceDataSource function takes the longest time on the first layer the others go really fast. I tried multiple MXD's.

Any idea what is wrong with the code?
0 Kudos
1 Solution

Accepted Solutions
BillSouter
New Contributor II
I'm not sure if you're still having this problem or not, but I recently had a similar issue using layer.replaceDataSource in a loop to replace SDE connections. It was only updating the first layer correctly but wouldn't update any other layers using the same SDE connection file.

The solution that worked for me was to use arcpy.ClearWorkspaceCache_management() at the end of my loop prior to getting the next layer.

Hope this helps,

Bill

View solution in original post

0 Kudos
6 Replies
JeffBarrette
Esri Regular Contributor
It would be nice to see the functions as well.

What is the value of your newDBPath?  They should be just the name of the dataset, not the data source.  Perhaps you could change the value to equal layer.datasetName.

Jeff
0 Kudos
JeroenWisse
New Contributor
Thanks for your reply.
Unfortunately i am not at my work pc (it's evening over here) so i can't give you the relevant code.

I will do that tomorrow morning.
0 Kudos
JeroenWisse
New Contributor
It would be nice to see the functions as well.

What is the value of your newDBPath?  They should be just the name of the dataset, not the data source.  Perhaps you could change the value to equal layer.datasetName.

Jeff


The function findNewPath searches a csv file for the new connection and featureclass name.
The newDBPath contains just the name of the feature class /table etc.
Some examples of the newDBPath:

GEONAM_BDMSNRSNRGRD
GEONAM_BDMSNRGRNDCONVRNVLK
GEONAM_WTRSANCONGRDWTRVLK

newDBconnection="Database Connections\\xyz@geooraont.sde\\"

As you can see there is no dataset there which is how it should be.
The newDBConnection is the connection to the sde. Also without any datasets.

If i look at the mxd after i run the script it shows the following:

The first layer is set correctly without any dataset
see the attachment datasourceOK

The other layers are set incorrectly see for an example the attachment datasourceNotOK
Notice that the feature dataset is still set
0 Kudos
JeroenWisse
New Contributor
I guess no one has an idea of how to fix it?

Does it work for other users?
0 Kudos
BillSouter
New Contributor II
I'm not sure if you're still having this problem or not, but I recently had a similar issue using layer.replaceDataSource in a loop to replace SDE connections. It was only updating the first layer correctly but wouldn't update any other layers using the same SDE connection file.

The solution that worked for me was to use arcpy.ClearWorkspaceCache_management() at the end of my loop prior to getting the next layer.

Hope this helps,

Bill
0 Kudos
JeroenWisse
New Contributor
Hi,

Thanks for your answer I still had problems and your solution seems to work.
The only problem now is that python seems to crash at some points but the solution seems to work.
0 Kudos