Replace data sources from one sde to another

1545
7
01-11-2012 05:37 AM
by Anonymous User
Not applicable
Original User: keoe

Hi,

I have moved som data from one ArcSDE-geodatabase to another. In the new geodatabase the feature classes has new owner. With the code I have change to a new connection file but how to change the owner? The feature classes has the same name as before

path = u'C:/temp/Test/'

for dir, subdirs, files in os.walk(path):
    for f in files:
        if f.endswith('.mxd'):
            filename = os.path.join(dir, f)
            print filename
            mxd = arcpy.mapping.MapDocument(filename)
            mxd.findAndReplaceWorkspacePaths(r"C:\CONNECTIONS\OLD_CONNECTION.SDE", r"C:\CONNECTIONS\NEW_CONNECTION.sde", False)
            mxd.save()
0 Kudos
7 Replies
by Anonymous User
Not applicable
Original User: jbarrette

I assume you are not trying to change the owner of the data, you are simply changing the user/password info associated with the connections file.  Your new connection file should have that new info.  Is it not working? 

At 10.04 SP4 we fixed and issue (NIM075806) where arcpy.mapping mxd.replaceWorkspaces fails when moving from one workspace to a different workspace when the "to" workspace is not the owner user account.  A work around is to do the repair in a two step process: 1) go from owner on workspace1 to owner on workspace2 and then 2) go from owner on workspace2 to user on workspace2.  In other words, make one change at a time.

I'm not sure this is your issue if you are trying to set the user to be the owner.

Here is some code:

connection1 = SQLasOwner
connection2 = OracleAsOwner
connection3 = OracleAsuser
mxd = arcpy.mapping.MapDocument(relPath + r"\SQLServer.mxd")
mxd.replaceWorkspaces(connection1, "SDE_WORKSPACE", connection2, "SDE_WORKSPACE")
mxd.replaceWorkspaces(connection2, "SDE_WORKSPACE", connection3, "SDE_WORKSPACE")


Jeff
0 Kudos
MichaelVolz
Esteemed Contributor
Jeff:

Does ESRI have a tentative date of when service pack will be available to all users?

Does this push back the date of release of ArcGIS v10.1?

Your feedback is greatly appreciated.  Thanks.
0 Kudos
by Anonymous User
Not applicable
Original User: jbarrette

10.0 SP4 and the 10.1 release are really independent of one another.  Esri will often produce SPs for releases older than the current release.

SP4 and 10.1 PreRelease will coincidently both be available later in Q1.
0 Kudos
KlasÖstergren
New Contributor III
I assume you are not trying to change the owner of the data, you are simply changing the user/password info associated with the connections file.  Your new connection file should have that new info.  Is it not working? 

At 10.04 SP4 we fixed and issue (NIM075806) where arcpy.mapping mxd.replaceWorkspaces fails when moving from one workspace to a different workspace when the "to" workspace is not the owner user account.  A work around is to do the repair in a two step process: 1) go from owner on workspace1 to owner on workspace2 and then 2) go from owner on workspace2 to user on workspace2.  In other words, make one change at a time.

I'm not sure this is your issue if you are trying to set the user to be the owner.

Here is some code:

connection1 = SQLasOwner
connection2 = OracleAsOwner
connection3 = OracleAsuser
mxd = arcpy.mapping.MapDocument(relPath + r"\SQLServer.mxd")
mxd.replaceWorkspaces(connection1, "SDE_WORKSPACE", connection2, "SDE_WORKSPACE")
mxd.replaceWorkspaces(connection2, "SDE_WORKSPACE", connection3, "SDE_WORKSPACE")


Jeff


I clarify with an example:
In database1 the name of the featureclass is AAA.roads
In database2 the name of the same featureclas is BBB.roads

How can I handle this woth python?
0 Kudos
by Anonymous User
Not applicable
Original User: jbarrette

When the name of the dataset changes, you must use layer.replaceDataSource (or table.replaceDataSource).

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Updating_and_fixing_data_sources_with_...

Here is a sample from the second link under the section called "A feature class is renamed".  In your example, "Highways" would be replaced by "BBB.Roads" or just "BBB".

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
for lyr in arcpy.mapping.ListBrokenDataSources(mxd):
    if lyr.supports("DATASOURCE"):
        if lyr.dataSource == r"C:\Project\Data\Transportation.gdb\MajorRoads":
            lyr.replaceDataSource(r"C:\Project\Data\Transportation.gdb", "FILEGDB_WORKSPACE", "Highways")
            lyr.name = "Highways"
mxd.saveACopy(r"C:\Project\Project2.mxd")
del mxd


Jeff
0 Kudos
MichaelVolz
Esteemed Contributor
Jeff:

Do you have to use mxd.saveACopy(r"C:\Project\Project2.mxd") in order for this script to replace the datasource?

I would like to create a similar python script, but I do not want to create an additional copy of the file as users could have short-cuts on their desktops to the mxd which would now be broken.  Can I just overwrite the existing mxd instead of creating a new mxd?

Your feedback is greatly appreciated.  Thanks.

Mike
0 Kudos
by Anonymous User
Not applicable
Original User: jbarrette

Use mxd.save() instead.  Saving is not necessary for repair to work.  It is possible to repair on the fly, print, export, etc and then not save changes.

Jeff
0 Kudos