I have an ArcMap user that uses the script below.
The script works in ArcMap interactive python window but does not works in stand alone script mode (cmd).
It throws a RuntimeError while accessing a FeatureClass in SQL Server geodatabase.
from datetime import date, timedelta, datetime
#fcView = u"D:\\apps\\DailyProgress\\email@example.com\\SMFFMIS.dbo.vw_OutstandingWO"
fcWO = u"D:\\apps\\DailyProgress\\firstname.lastname@example.org\\POLYPIP_OPT.sde.GeoOutstandingWO"
fields = ["ID","SpkNumber","SpkItemNo","Contractor","KeyID","Rotation","ProjectNetwork","OperationActivity","Remark","SpkStartDate","SpkFinishDate","Qty","ActualWork","Nama_Pengawas","PERNR","PlantCode","DistrictCode","CompanyCode","CRT_Date","MOD_Date","MOD_UserID","isDone","SHAPE"]
rowsInsert = arcpy.da.SearchCursor(fcWO, fields) # error producing code
for row in rowsInsert:
What is not working in the stand alone script
Accessing cursors return a RuntimeError.
arcpy.Describe raises an IOError.
arcpy.GetCount_management and few others GP Tools raises an arcgisscripting.ExecuteError.
What is working in the stand alone script
arcpy.ListFeatureClasses successfully returned the feature classes in the geodatabase.
Windows server 2008 R2 64 bit
SQL Server 2012
The geodatabase created using ArcGIS 10.4.1's Python
What we did
1. Reinstall the ArcMap. Result: not working.
2. Suspected the environment variables. Tried to copy the sys.path of the desktop to the stand alone script. Result: not working.
3. By chances, we found the solution is to run the arcpy.GetCount_management twice (after the first one raises an error).
4. We're doing step (3) as a work around and still trying to reproduce the error.
It seems that there is an additional steps used by ArcMap to connect to the database, which is not present in the stand alone (cmd) mode.
What I want to ask
1. How to resolve the problems, what is happening there?
Figure 1 Displaying the first entry of the row in ArcMap’s Python window.
Figure 2 RuntimeError when executed as stand alone script via command prompt.
Figure 3 IOError when using arcpy.Describe()
Figure 4 Using arcpy.GetCount_management() raise an arcgisscripting.Exception, but works if repeated after the exception.
Figure 5 After exception was raised in figure 4, all of the subsequent code was working!
Thankyou for your attention..