Creation of database connection does not work on ArcGIS Server 11

620
3
04-04-2023 04:20 AM
Labels (1)
Cristian_Galindo
Occasional Contributor III

I have a snippet that creates a database connection to an enterprise geodatabase, then list the tables:

import arcpy
new_conn2 = arcpy.management.CreateDatabaseConnection(r"c:\temp", "Myconnection2", "SQL_SERVER", "MySQLServer",                                           account_authentication="DATABASE_AUTH",
                                          username="myUser", 
                                          password="mySecretPassword", 
                                          save_user_pass="SAVE_USERNAME", database="myEGDB")
print(arcpy.Describe(new_conn2[0]).dataElementType)
arcpy.env.workspace = new_conn2[0]

# Get and print a list of tables
tables = arcpy.ListTables()
for table in tables:
    print(table)

 

the output when I run the snippet in ArcGIS Pro 3.0 is:

'DEWorkspace'
DATAOWNER.P_Centerline_Sequence
DATAOWNER.P_DocumentPoint__ATTACH
DATAOWNER.P_CasingInspection
DATAOWNER.P_CPBondInspection
DATAOWNER.P_CPRectifierInspection
DATAOWNER.P_CPTestPointReading
DATAOWNER.P_CrossingInspection
DATAOWNER.P_ElectricSurvey
DATAOWNER.P_ExcavationDamage__ATTACH
DATAOWNER.P_ExposedPipeInspect__ATTACH
DATAOWNER.P_GasLeak__ATTACH
DATAOWNER.P_GasLeakInspect
.....

 

When I run the same code in ArcGIS Server python instance the output is:

'DEFile'

 

I tried using the Python3 command prompt as well as the Jupyter notebook present in the ArcGIS Server installation.

@BrianClee  or @GhislainPrince  do you have any idea about this?

0 Kudos
3 Replies
Cristian_Galindo
Occasional Contributor III

Following the recommendation of the page https://enterprise.arcgis.com/en/system-requirements/latest/windows/database-requirements-sqlserver.... I downloaded from Microsoft site the latest version of the ODBC driver version 18, that is the one that I installed in both machines (Client and Server):

2023-04-04_14-33-54.png

A colleague  recommend me to install the ODBC driver provided by ESRI, I proceed to install it:

2023-04-04_14-37-08.png
 

Now the result of the snippet is the one expected:

2023-04-04_14-39-09.png

 

Conclusion: ArcGIS server 11 has an issue with the ODBC Driver version 18.6.3

0 Kudos
avonmoos
Occasional Contributor

Did you try to set the workspace as a variable instead of creating the 'CreateDatabaseConnection()' command?

import arcpy

# Create a database connection to an enterprise geodatabase
db_path = r"c:\temp\Myconnection2.sde"
arcpy.management.CreateDatabaseConnection(db_path, "Myconnection2", "SQL_SERVER", "MySQLServer",
account_authentication="DATABASE_AUTH",
username="myUser",
password="mySecretPassword",
save_user_pass="SAVE_USERNAME", database="myEGDB")

# Set the workspace to the database connection file path
arcpy.env.workspace = db_path

# Get and print a list of tables
tables = arcpy.ListTables()
for table in tables:
print(table)
0 Kudos
Cristian_Galindo
Occasional Contributor III

Hello, 

Yes I tried what you mentioned, but I thought I had a typo in my code I decided to use the path generated by the tool that creates the file.

But in order to understand the logic behind your suggestion, could you explain me why using the result of the tool's execution would be an issue?

0 Kudos