Select to view content in your preferred language

Scripts works in ArcMap Python's window, but failed in the command prompt?

812
2
07-12-2018 04:33 AM
KeenanGebze1
Emerging Contributor

Hi,

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.

import arcpy

import datetime

from datetime import date, timedelta, datetime

import time

#fcView = u"D:\\apps\\DailyProgress\\sa@gkmgsa3.sde\\SMFFMIS.dbo.vw_OutstandingWO"

fcWO = u"D:\\apps\\DailyProgress\\sde@gkmgsa3.sde\\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:

  print(row)

del 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.

The environment

 

Operating System

Windows server 2008 R2 64 bit

ArcMap

10.4.1

Python

C:\Python27\ArcGIS10.4

Database

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.

My suspicion

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?

Images

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!

Workspace properties

connectionProperties.authentication_mode

DBMS

Database

POLYPIP_OPT

historical_timestampe

Exception

connectionProperties.isGeodatabase

True

connectionProperties.instance

sde:sqlserver:gkmgsa3

connectionProperties.server

gkmgsa3

connectionProperties.user

sde

connectionProperties.version

sde.Default

connectionProperties.connectionString

 

currentRelease

True

Domains

[]

Release

3,0,0

workspaceFactoryProgID

esriDataSourcesGDB.SdeWorkspaceFactory.1

workspaceType

RemoteDatabase

Thankyou for your attention..

Regards,

2 Replies
DanPatterson_Retired
MVP Emeritus

have you got a python IDE associated with ArcMap?  It is almost like you have a disconnect with python. 

0 Kudos
KeenanGebze1
Emerging Contributor

Hi Dan,

What do you mean by associated with ArcMap? Is it when the IDE default path is in the C:\\Python27\ArcGIS10.4\... ?

I think the user has IDLE Python.

But the script itself is executed on the command prompt..

0 Kudos