I have the following code.
The code works great on a shapefile but as soon as i change the workspace to a SDE sqlexpress datatbase i get the following error.
The error is not specific on where the problem is, I've searched but i am unable to find the problem. where is the problem and how can i fix it to run with out errors?
As i mentioned before the code runs great against a shapefile and running against a shapefile takes about 4-6 seconds.
When i switch it to a SDE sqlexpress datatbase it takes 4 minutes then runs into the error. There is only 48 features in the SDE sqlexpress datatbase so the database is not very big. Why is this?
The code works great on a shapefile but as soon as i change the workspace to a SDE sqlexpress datatbase i get the following error.
Code:
Traceback (most recent call last):
File "C:\GIS\Python Scripts\AddressPoints\Point_2_Ca.py", line 125, in <module>
edit.stopOperation()
SystemError: error return without exception set
As i mentioned before the code runs great against a shapefile and running against a shapefile takes about 4-6 seconds.
When i switch it to a SDE sqlexpress datatbase it takes 4 minutes then runs into the error. There is only 48 features in the SDE sqlexpress datatbase so the database is not very big. Why is this?
Code:
import arcpy
from arcpy import env
import time
import datetime
import pythonaddins
import os
fc = "TonyTwoWay.DBO.TT"
workspace = r"Database Servers\DSD15_SQLEXPRESS.gds\TonyTwoWay (VERSION:dbo.DEFAULT)"
arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False
# Start an edit session. Must provide the worksapce.
edit = arcpy.da.Editor(workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
input = arcpy.GetParameterAsText(0)
rows = arcpy.SearchCursor(input)
for row in rows:
geom = row.Shape
X = geom.centroid.X
Y = geom.centroid.Y
del rows, row
row_values = (X, Y, (X, Y))
cursor = arcpy.da.InsertCursor(fc, ["X_Coord", "Y_Coord", "SHAPE@XY"])
cursor.insertRow(row_values)
del cursor
####Select by location on parcels with created point
Parcellyr = "Taxparcels"
arcpy.MakeFeatureLayer_management(Parcellyr, "in_memory\Parcel layer")
entries = int(arcpy.GetCount_management(fc).getOutput(0))
for i in xrange(entries):
arcpy.MakeFeatureLayer_management(fc, "in_memory\point layer", "\"OBJECTID\"={}".format(str(i) + ""))
arcpy.SelectLayerByLocation_management("in_memory\Parcel layer", "INTERSECT", "in_memory\point layer", "", "NEW_SELECTION")
#if arcpy.Exists(pt_lyr): arcpy.Delete_management(pt_lyr)
arcpy.CopyFeatures_management("in_memory\Parcel layer", "in_memory\Sel_Par")
table = "Vector.DBO.PARCELADMIN"
try:
arcpy.AddJoin_management("in_memory\Sel_Par", "ACCOUNT", table, "Acct", "KEEP_COMMON")
except BaseException as e:
pass
arcpy.CopyFeatures_management("in_memory\Sel_Par","in_memory\ParLYR")
arcpy.MakeFeatureLayer_management("in_memory\ParLYR", "in_memory\Par")
#### populates fields
add_fields = ["ACCOUNT","SiteNum","OwnerName","SiteAddres","SiteNumSfx","SiteStreet","Predir","StreetType","Postdir", "SubName", "SiteCity", "SiteZip", "SubName"]
# fix args
if not isinstance(add_fields, list):
# from script tool
add_fields = add_fields.split(';')
# do not need this scratch file
fcOutput = r'C:\Temp\Default.gdb\temp_join' #'temp_join' when using workspace = r"C:\Temp\default.gdb"
arcpy.SpatialJoin_analysis("in_memory\Par", "in_memory\point layer", fcOutput, 'JOIN_ONE_TO_MANY', 'KEEP_COMMON')
# grab oid field from points
oid_t = arcpy.Describe(fc).OIDFieldName
Field4 = "SubNum" #Field from spaital Join
Field4a = "SiteSubNum"
#Field5 = "City" #Field from spaital Join
#Field5a = "BusinsName"
# init rowW and rowR
curR = arcpy.SearchCursor(fcOutput)
join_dict = dict([(r.JOIN_FID,[r.getValue(f) for f in add_fields]) for r in curR])
del curR
Fields = ["SubNum","City",]
rows = arcpy.da.SearchCursor(fcOutput, Fields)
for row in rows:
Num1 = rows[0]
#Num2 = rows[1]
# Now update the new target
curW = arcpy.UpdateCursor(fc)
for row in curW:
t_oid = row.getValue(oid_t)
if t_oid in join_dict:
for f in add_fields:
row.setValue(f, join_dict[t_oid][add_fields.index(f)])
row.setValue('GIS_STEW', "Canyon Co")
row.setValue('IssuedBy', "TA")
row.setValue('Status', "Active")
row.setValue('StartDate', datetime.datetime.now().strftime('%m/%d/%Y'))
row.setValue('SiteState', "ID")
row.setValue('SiteCounty', "Canyon")
row.setValue('StreetName', row.SiteStreet + " " + row.StreetType)
row.setValue('Verified', "Yes,TA")
row.setValue(Field4a, Num1)
#row.setValue(Field5a, Num2)
#else:
#row.StreetName = curR.SiteStreet
curW.updateRow(row)
del row, curW, rows
#arcpy.SelectLayerByAttribute_management(Parcellyr, "CLEAR_SELECTION")
arcpy.Delete_management("in_memory\Parcel layer")
arcpy.Delete_management("in_memory\point layer")
arcpy.Delete_management("in_memory\Sel_Par")
arcpy.Delete_management("in_memory\ParLYR")
arcpy.Delete_management("in_memory\Par")
#arcpy.Delete_management(r'in_memory\temp_join')
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)