Create sde feature class from SQL Server table with ArcPy

1090
2
04-05-2022 03:15 PM
CaraWiebalk
New Contributor II

I am trying to take data from a table in SQL Server and create a feature class in an enterprise geodatabase. I'm having issues *I think* with trying to reference a SQL Server table in tools that are expecting a filepath to a table.

I have tried using "MakeXYEventLayer", "MakeQueryLayer", "XYTabletoPoint" and I keep getting errors.

After some reading I think part of the issue is that these tools are looking for a table but I may still need to put a query on the SQL table to get the right results. I'm pretty new to SQL Server tables so I'm not sure.

I think the steps should be:

  1. Create a table view from the SQL Server table.
  2. Use that table view in XYTabletoPoint.
    1. ^if possible, this seems the most straightforward. If not I could use one of the other tools I mentioned and then use feature class to feature class
  3. Convert the output of XYTabletoPoint to be a feature class in the sde I already have.

Is this correct? Can I see an example of how the parameters would be formatted? Example of how I've tried it below:

  • IP address of the server - xxx.xxx.x.xxx
  • Database name - yyyy
  • Table name - zzz

For input table/input parameters I've tried:  xxx.xxx.x.xxx\yyyy\zzzz and xxx.xxx.x.xxx.yyyy.zzzz; setting the IP address/database as the environment workspace then just zzzz; and setting just the IP address as the environment workspace then just yyyy.zzzz and yyyy\zzzz

0 Kudos
2 Replies
MarcGraham2
Occasional Contributor III

Hi,

You need to reference a database connection file rather than the IP address: https://enterprise.arcgis.com/en/server/latest/manage-data/windows/connect-sqlserver.htm

Regards,

Marc

CaraWiebalk
New Contributor II

Thank you! I didn't get a notification about this and only just saw this now. I had figured out a workaround but this is useful for the future.

I ended up following the steps listed here (https://datatofish.com/export-sql-table-to-csv-python/) and used pyodbc and pandas functions to export the SQL server table into a csv which I could then use with arcpy functions.

0 Kudos