Tuesday, 12 May 2015

arcpy - Create an ArcCatalog OLE DB Connection using Python


Is it possible to create an OLE DB connection (*.odc) to a database in ArcGIS 10 , but using Python instead of the ArcCatalog GUI wizard? I don't need to necessarily create a file on disk, just make the connection to the database. I am trying to automate a procedure that many users may use, and do not want to rely on every user remembering to create the OLE DB connection manually through ArcCatalog.


The Python code provided by @blord-castillo in a similar question shows How to create an SDE Connection using Python, so I am looking for something similar that creates an OLE DB connection. I cannot seem to find any reference to any Python code for this task.


Eventually, the python code sample using Make Query Table is basically what I want to do, but it assumes you already have your *.odc connection built.


Anyone have suggestions or pointers for places to look for sample code? I am working against a SQL Server database, in case that matters.



Answer



Can you use arcpy 10.1 yet? OLEDB connections are created as .sde files at 10.1 using a new function: http://resourcesbeta.arcgis.com/en/help/main/10.1/index.html#/Create_Database_Connection/00170000016q000000/


arcpy.CreateDatabaseCOnnection_management("C:\\MyDirectory", "test.sde", "SQL_SERVER", "servername", "DATABASE_AUTH", "MyUserId", "MyPassword", "SAVE_USERNAME", "databasename")

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...