TransWikia.com

arcpy.da.InsertCursor() Fails with SDE But Works with Local FGDB

Geographic Information Systems Asked by PacmanKX on January 22, 2021

I am trying to use arcpy.da.InsertCursor() to insert rows to an SDE table but no rows were added and without any error message. I tried the same code with an exact replica table in a local FGDB and it worked fine. The code is simple:

workspace = r"Database ConnectionsSDE.sde"
arcpy.env.workspace = workspace
arcpy.env.overwriteOutput = True

edit = arcpy.da.Editor(workspace)
edit.startEditing(False, True)
edit.startOperation()

cursor = arcpy.da.InsertCursor(sde_table, ["Date_"])
cursor.insertRow(["10/21/2020"])

I also tried to use arcpy.InsertCursor() and it works well in both SDE and local FGDB. Is there anything missing for getting arcpy.da.InsertCursor() to work in SDE?

RDBMS: SQL Server 2012

Python: 2.7

SDE: 10.6.1

One Answer

import arcpy
import os

fc = r'Database ConnectionsConnection to sde.sdetable'
workspace = os.path.dirname(fc)


edit = arcpy.da.Editor(workspace)


edit.startEditing(False, True)


edit.startOperation()


with arcpy.da.InsertCursor(fc, ('field1', 'field2')) as cursor:
    cursor.insertRow(("string1", "string2"))



edit.stopOperation()


edit.stopEditing(True)

The above code should work for you. just replace the SDE location, field1 and field2 and finally the string1 and string2

Answered by Ram on January 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP