Select to view content in your preferred language

Changing SDE Connection Name in Catalog doesn't change Connection for Feature classes

1069
3
05-09-2012 10:14 PM
DorotheeKemnitz
Emerging Contributor
Hi everyone,

I just created a little Python tool to change the workspace of files in my mxds from my Staging Environment to the Production Environment so I don't have to open up the mxds manually and change them that way. Anyway while I was working on it I was wondering why there are always a couple files that won't change their workspace. I tried the tool in IDLE and checked for the workspace for each feature class and noticed there are older SDE Connection names listed as my workspace for some files.

Basically I had my SDE databases called Old_Staging and changed it to New_Staging after a while. In between I added data to the database. Now the files that were added while the connection was called Old_Staging it's still called Database Connections\Old_Staging.sde .

This makes it very annoying to write tools because you have to make sure you include all possible names.

What happens if someone else adds data and they have named their database differently?
Is there a way of changing those feature class workspaces?

I find it very strange that you can change so easily the connection in ArcCatalog but then again it doesn't change the workspace name for the files in it.

Cheers,
Dorothee
0 Kudos
3 Replies
F__BenGrieger
Deactivated User
I'm not sure if this gets at what you are having trouble with, but you haven't gotten a reply, so I'll give it a go.  First, changing the name of your sde connection will generally not change the data sources for the items in your table of contents. The connection name is just a name and can be changed to whatever you want just like the layers in the table of contents can be called whatever you want regardless of the actual name of the data. However, if you add another connection to a different SDE database, then manually go to each layer 'properties' and set the data source, it should change it- but of course that is pretty cumbersome.

One way to change the data sources for all your layers in bulk is to use arcCatalogue, right-click on your .mxd, and select "Set Data Source(s)..."  The rest of the process is pretty obvious once you get there- you can highlight just one of the layers or highlight all of them to change them. The .mxd will carry this connection information with it. 

Another approach is to stop serving your old versions of the database (a good practice anyway to prevent confusion like this...), open the .mxd which will create red exclamation points on all the layers that were using the old data source, right-click one of them and select "Repair Data Source". Then navigate to the correct source. It should then automatically correct all of them that failed if it can find equivalent feature classes at the new source. The new source info will then be carried in the .mxd.

I hope this is helpful- forgive me if I misunderstood your question or told you things you already know!

If you're working on making this happen with a script, I'd like to see it when you're done!
0 Kudos
DorotheeKemnitz
Emerging Contributor
Hi zenben,

Thanks for your reply. But unfortunately it's not exactly what I am looking for.

If you have a look at the attachments maybe you see what I mean. SDEConnections is a screenshot of my connections the way they are listed under the "Documents and Settings" App folder. Those are the same names as in my ArcCatalog connection seen in the CatalogConnection Screenshot. To reference to your SDE connections in a python script you can either use the path to your documents and settings folder or you can say Database Connections/Your Connection.sde. But when I referenced to either, Database Connections/Technical Data.sde or any other connection shown in the attachment it would give me an error. So I listed the workspaces with a python tool:

for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.supports("WORKSPACEPATH"):
        print lyr.workspacePath

This tool gave me the workpath for each file in my mxd. But that's when I noticed that this is the reason why it doesn't work. (See attachment DataConnection) The 02_Reference.sde is the same as Reference Data.sde but before I named it Reference Data.sde I called it 02_Reference in Catalog. Then I uploaded files to the database and then changed the name to Reference Data.sde. But somehow the name that you have set your database connection to will stick to your layer that you upload. Basically when I run the python script it should tell me instead of 02_Reference.sde the connection is called Reference Data.sde, because obviously there isn't a connection anymore that is called 02_Reference.sde (see SDEConnections.jpg).

Do you understand what I mean? It's just very frustrating to spend a lot of time on a tool that doesn't work just to find out it's something absurd like that. So now back to my original question, what happens to data which is uploaded by a different user and obviously everyone can name their databases in Catalog differently?
0 Kudos
MichaelVolz
Esteemed Contributor
To try to minimize problems like this in the future, you should try to make standardized naming conventions for SDE connections in ArcCatalog.  In this way you would not need to find out what each user named their similar SDE connections.
0 Kudos