How to handle sde database connections?

3380
5
04-29-2016 05:43 AM
BradJones
New Contributor III

I'm about ready to deploy an add-in but I'm not sure how to handle database connections.  I know I can include files used by the add-in (ArcCatalog database connection file?) in the install directory for packaging when the add-in file is created, but how do i code the file location?  I can include the path to the file that is used while developing, but won't that change when it's all packaged into the .esriaddin file?  Also, "in_memory" doesn't work.

Thanks

0 Kudos
5 Replies
WesMiller
Regular Contributor III

Use Create ArcSDE Connection File—Help | ArcGIS for Desktop this is the best way to handle server connections that I've found. Place the connection file in a central location that all users can access. I've been able to use "in_memory workspace in add-ins do you have an example of what you are trying to do?

0 Kudos
BradJones
New Contributor III

When I said in_memory doesn't work I meant as the out_folder_path with CreateDatabaseConnection_management. 

We restrict most users to .lyr files which have the database connections included in the file.

In the Python add-in documentation:

File and folder structure

Packaging data and toolboxes in the install directory would be pretty handy in this situation. 

I could create the file in a directory then delete it after.  

0 Kudos
WesMiller
Regular Contributor III

Just as a thought you could put the connection file in the same directory as the .lyr files that your users already have access.

0 Kudos
BradJones
New Contributor III

Yeah, I think that's what I will do.  The idea of having everything in one file that I could send to people that they could double click and install was enticing.

0 Kudos
WesMiller
Regular Contributor III

You could store the connection file with your script and get the home path of the script see below. That would take away the ability to use it somewhere else.

hmpath = os.path.realpath(__file__)
h,t = os.path.split(hmpath)
0 Kudos