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?
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):
Now the result of the snippet is the one expected:
Conclusion: ArcGIS server 11 has an issue with the ODBC Driver version 18.6.3
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)
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?