Access EGDB from SDE regardless of filepath

221
4
3 weeks ago
sbrowneotogo
New Contributor

I've created a python toolbox that pulls data from an enterprise GDB, defined by an SDE file.

SDE_connection = os.path.join(SDE_dir, 'mydb_database.windows.net.sde')

my_gdb = os.path.join(SDE_connection, 'my_table')
arcpy.conversion.ExportTable(my_gdb, some_filepath)

This works fine, however I recently realized when trying to run this toolbox on someone else's computer that Arcpy treats os.path.join('C:\Computer1\my_project', SDE_connection, my_gdb) as being a completely different table than os.path.join('C:\Computer2\my_project', SDE_connection, my_gdb). Trying to access data from the second one results in a table not found error.

I originally created the table in the EGDB with something like: arcpy.conversion.ExportTable(csv_filepath, my_gdb)

How do I use an SDE to access data regardless of the exact filepath to the SDE?

0 Kudos
4 Replies
RhettZufelt
MVP Frequent Contributor

One way is to put a copy of the SDE connection file on a network drive that everyone has access to, then use the full network path to that SDE connection file as input to the toolbox.

R_

BlakeTerhune
MVP Regular Contributor

If everyone is using the same database connection and it's not changing often, maybe you can create the database connection in the script when it's run? Just output to a temp directory that will get cleaned up when the script finishes. Or you can try a database connection string instead of using .sde files.

sbrowneotogo
New Contributor

The problem is we need to pull data from the GDB to the users workspace when the tool runs, so they can't just create a new one each time. We all need to be accessing the same table. I'm trying out using a database connection string but unable to figure out how to create a GDB with a connection string.

0 Kudos
BlakeTerhune
MVP Regular Contributor

Then add an input parameter (DEWorkspace) and have the user set the database connection manually to whatever they want.

0 Kudos