I'm trying to access a database located on a remote server.

I used ArcMap "Create Database Connection" tool on my computer to create a SDE file and I want to use a script to add some data to a table located on this remote database.

On the server SQLEXPRESS

there is a database called WeatherData (the SDE file is used to access this database)

and in this database there is a table called Weather1.

Image not working

I'm currently using this script :

import os
import arcpy
from arcpy import env

directory = os.path.dirname(os.path.realpath(__file__))
arcpy.env.workspace = os.path.join(directory, "SqlServerConnect_UserAuthentication.sde")

table = "Weather1"
tableLocation = os.path.join(arcpy.env.workspace, table)

print arcpy.env.workspace
print tableLocation
print arcpy.ListTables()

arcpy.env.workspace and tableLocation are printed correctly, but arcpy.ListTables() print an empty list


which I guess means the script didn't find anything in the workspace. (or couldn't connect to it)

Afterwards, I just want to add some data to the table using another arcpy function

data = os.path.join(directory, "test.csv")
arcpy.Append_management (data, tableLocation, "NO_TEST")

Of course I get an error : (translated from french)

Traceback (most recent call last):
File "C:\Users\...\ArcGISApp\test.py", line 28, in <module>
arcpy.Append_management (data, tableLocation, "NO_TEST")
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 3785, in Append
raise e
arcgisscripting.ExecuteError: Execution Error. Incorrect parameters
ERROR 000732: Dataset C:\Users\...\ArcGISApp\SqlServerConnect_UserAuthentication.sde
does not exist or is not supported
Execution Error(Append).

So how I am I supposed to use the SDE file to access the database (and the table) correctly ?

  • stackoverflow.com/questions/11278114/… It may be due to the port number being blocked. Before I'd blame ArcPy I'd use sql management console and make sure I can see the remote database first. – Bill Chappell Apr 25 '17 at 12:31
  • I just tried to create a connection file to the same database with arcpy.CreateDatabaseConnection_management() and it worked so the port shouldn't be blocked – Kuromax Apr 25 '17 at 12:56
  • Use the .SDE file you just made. Do not use the .gds file from the Database Servers node for general data use. While you can, its really a better practice to save the .gds file for administration and use the .sde for data access (read/write) -- oh edit, I see in your script you're using .SDE, but your screen shot shows the .gds – KHibma Apr 25 '17 at 12:57
  • The .gds was just to show were the data was located, I'm using the connection file to connect to the WeatherData database which is IN the server "SQLEXPRESS.gds". (likewise, the table "Weather1" is in the "WeatherData" database) – Kuromax Apr 25 '17 at 13:18

Ok so the error 732 was caused by the fact I inputted :

table = "Weather1"

when I should have used instead

table = "WeatherData.DBO.Weather1" (or at least "DBO.Weather1")

It then led to an error 229 which was caused by the fact that the user I used in the SDE file was able to access the database but couldn't see what was inside

When I changed the SDE file to one with another user with adequate rights it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.