Problem with arcpy.CreateDatabaseConnection_management

2136
4
Jump to solution
03-09-2017 09:24 AM
TimWieland
New Contributor
 print "Creating SDE database connection properties file"
                arcpy.CreateDatabaseConnection_management(out_folder_path=os.getcwd(), out_name=Connection_File_Name, database_platform=database_type, instance=instance, database="", account_authentication="DATABASE_AUTH", username=dbms_admin, password=dbms_admin_pwd, save_user_pass="TRUE")
                if arcpy.Exists("Database Connections\\" + Connection_File_Name):
                        print "Current SDE connection was created and database connection successful"
                        sys.exit()
                else:
                        # Don't hard exit on failure.  If creating a "system" sde file arcpy exist does not work correctly.
                        print "Unable to validate connection to SDE database. There could be a problem with the sde file"
                        sys.exit()

We are currently working a project to upgrade from Oracle 11g to 12c, and ESRI 10.0 to 10.4.  In the previous environment our developers had a python script used as part of our install process that created and validated and SDE connection to the Oracle database.  The python script has been tweaked for ESRI 10.4 / Oracle 12c.  We are unable to get a connection using the script, but can connect from the server running ESRI 10.4 to the Oracle 12c database from both SQLPLUS and through ArcMAP.  Above is the section of the script that is failing (we constantly get the "Unable to validate connection to SDE database).

Any thoughts on what may be wrong would be greatly appreciated.  We are using the 32-bit Oracle client for the connection, but can't get it to work from the python script.  Thanks for any help !!!

Tim

0 Kudos
1 Solution

Accepted Solutions
BlakeTerhune
MVP Regular Contributor

Firstly, using the syntax highlighting feature of GeoNet makes it much easier to share readable code.

Next, you should print out the parameters you're using to create the connection file to make sure they are indeed what you want. You can also print arcpy.GetMessages() after you create the database connection to see if there are any errors or warnings from the tool.

Finally, your validation is assuming os.getcwd() is the same as the ArcGIS relative Database Connections folder; I wouldn't be so confident. It would be better to check the same directory in which you created the database connection file.

if arcpy.Exists(os.path.join(os.getcwd(), Connection_File_Name)):‍‍‍

View solution in original post

4 Replies
BlakeTerhune
MVP Regular Contributor

Firstly, using the syntax highlighting feature of GeoNet makes it much easier to share readable code.

Next, you should print out the parameters you're using to create the connection file to make sure they are indeed what you want. You can also print arcpy.GetMessages() after you create the database connection to see if there are any errors or warnings from the tool.

Finally, your validation is assuming os.getcwd() is the same as the ArcGIS relative Database Connections folder; I wouldn't be so confident. It would be better to check the same directory in which you created the database connection file.

if arcpy.Exists(os.path.join(os.getcwd(), Connection_File_Name)):‍‍‍
TimWieland
New Contributor

@Blake - Thanks for the tip on the syntax highlighting feature for the code - updated the original post.  Our developer is currently looking into the suggestions you made, thank you!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Since database is an optional parameter that only applies to PostgreSQL and SQL Server, and you are using Oracle, I would drop it altogether.  It could be that passing database="" when connecting to Oracle is causing an issue.

0 Kudos
TimWieland
New Contributor

Thanks Blake, your suggestions contributed to discovering that our issue was related to the SDE connection names not matching values in a script, problem is now solved!

0 Kudos