python script not run as a SQL Server scheduled job

6035
10
12-12-2012 01:25 PM
RobertHu
New Contributor II
Posted my problem in another forum (GP), and no luck. Try here.

Python 2.7
ArcGIS 10.1 (sp1)
ArcSDE 10.1 (sp1)
SQL Server 2008 R2 Standard (sp2)
Windows Server 2008 R2 Standard (sp1)

Run a batch file, which calls a python script, as SQL Server scheduled job. If the python script includes "import arcpy" statement, the script will fail without leaving any error message. The script works fine without the "import arcpy" statement. Tried same thing as a system scheduled task, the results are same.

While running the batch file from command line, it works fine with or without the "import arcpy" statement.

Anyone ever experienced same thing, and have a clue?

Thanks in advanced!
0 Kudos
10 Replies
RandyKreuziger
Occasional Contributor III
Are you running the scheduled task as yourself or a different user?  If a different user does that user have access to an ArcGIS Desktop license?
0 Kudos
RobertHu
New Contributor II
Hi Randy,

It is the same user. I used the same user to login the DB server, run the batch file from command prompt, run the SQL scheduled job, and run the system scheduled task. The one from command worked fine. The other two failed. What troubles me is that when it failed, it left nothing in the logfile, simply quit. Cannot collect any error message. So, don't know if it is the SQL Server problem (apparently not), user's issue (don't know), arcpy's settings (most likely), or something else.

By the way, thank you so much for trying to help me!
0 Kudos
SebastianRoberts
Occasional Contributor III
Were you able to solve this?
I have the identical system specs as you, and the identical problem.  All my SQL server scheduled jobs worked until we upgraded Desktop from 10.0 to 10.1 on the server where the jobs are scheduled.  Now the SQL server scheduled job which runs a python script fails as soon as I add an import arcpy statement.  I can run the script from IDLE, pythonWin, and with the identical operating system command that the SQL job uses:
C:\Python27\ArcGIS10.1\python.exe D:\Automate\Synchronize.py
  It seems like it must be a permssion issue of the AD account that I run the SQL job step as.  However, I logged on to the server with that AD account that the SQL job is running under, and I am able to open ArcMap, and able to run the python script as well.  Again the scheduled job can run a python script with a print statement, but as soon as I add "import arcpy" it fails.
0 Kudos
RobertHu
New Contributor II
Hi Sebastian,

Don't have a solution yet.

I opened a support request on 11/28, and worked with someone from ESRI geodata team for a few weeks. I was told at least one more user (probably you) experienced same thing, and a quite few tech support people got involved. They were able to reproduce my problem on their site, but couldn't figure out why or a work around. Since the issue is no longer a SQL agent job issue, they transferred my case to the Desktop team in late December. Now I'm still working with them for a solution.

You are right, it failed, and only failed, on "import arcpy" and the script being run as a background. Without this statement (or run it interactively), everything works fine.

By the way, the domain user I used to run the process is a member of the local administrator group on the DB server.

I'll let you know if a solution comes out. Thanks!
0 Kudos
FairfieldMapGuy
New Contributor
Did anyone get a solution form esri on this?  If so, could you post the solution.

Thanks in advance!
0 Kudos
SebastianRoberts
Occasional Contributor III
No resolution for me.  I worked many hours with a rather knowledgeable Esri support rep, and we couldn't find a solution.  However, because he can't reproduce on his system, no bug is logged.  I rescheduled all my jobs as Windows task scheduler jobs.  That took a lot of time, and was a significant compromise, because with Task scheduler it is much more difficult to get a status on fail/success of a step or job before moving to the next step or job.
0 Kudos
ShamonLarson
New Contributor
I am having an issue with this as well.

I just loaded ArcGIS Desktop 10.1 this past weekend.

The python scripts will not run from a scheduled SQL Server job using CmdExec or PowerShell, or even when packaged into an integration service (SSIS).

It will, however, run perfectly when called directly from command line, a PowerShell session, or even a PowerShell session that was started using the SQL Server Management Studio's "Start Powershell" command. It also runs from with a python window in ArcMap 10.1.

I can also run it from the Windows Task Scheduler with no problems.

I receive the following errors when the scheduled job in SQL Server executes:

[INDENT]Faulting application python.exe, version 0.0.0.0, time stamp 0x4df4ba7c, faulting module AfCore_libFNP.dll_unloaded, version 0.0.0.0, time stamp 0x4f920360, exception code 0xc0000005, fault offset 0x0de94eb4, process id 0xa38, application start time 0x01ce728082fce90c.

Faulting application python.exe, version 0.0.0.0, time stamp 0x4df4ba7c, faulting module unknown, version 0.0.0.0, time stamp 0x00000000, exception code 0xc0000005, fault offset 0x0dc8dc80, process id 0x%9, application start time 0x%10.[/INDENT]

Does anyone have any ideas?
0 Kudos
LinKuan_Jen
New Contributor
Try to grant user account access (account in which scheduled task run as) to python folder (c:\python2.x), I did not perform SQL Server scheduled job, but I successfully execute a python job from scheduled task to perform some arcpy task after doing this.

Hopefully this works in your case too.


Best Regards,
Bryant Lin
0 Kudos
LeonScott
New Contributor II
I have this same issue after upgrading SQL Server from 2005 to 2008 R2.  I am running ArcGIS 10.2


Leon
0 Kudos