ArcObjects fail when running scheduled task

3016
5
Jump to solution
09-22-2013 11:22 PM
JohanCarlsson
Occasional Contributor
Hi!

We have an application that is used to load shp to sde, sde to sde and sde to shp using the exes to perform these tasks. You can run this application via a GUI, or in silent mode through a .bat file and supplying the needed arguments (load, truncate, delete, version# etc). Running via the GUI works fine, running a .bat file works fine too, except when you try to schedule a task with it.

A scheduled task generates an error saying "Failed to initialize ArcObjects at ...". I've tried running the task scheduler with different user accounts (all of them admins on the machine), right clicking and running the scheduler as admin.

I am out of ideas and still haven't solved this. Is this a problem with ArcObjects or is it simply a problem with privileges for the user? Any help towards solving this would be greatly appreciated.

Regards
Johan Carlsson
0 Kudos
1 Solution

Accepted Solutions
JohanCarlsson
Occasional Contributor
It seems I have solved it, it was simply a question of the settings for the task.

[ATTACH=CONFIG]27779[/ATTACH]

"Run only when user is logged in" does not require highest privileges.
"Run wether user is logged in or not" requires the "Highest privileges"-checkbox to be checked for some reason. Old versions of the program I've been working on did not require this, can't really figure out whats different.

Thank you for your time Alexander!

View solution in original post

0 Kudos
5 Replies
AlexanderGray
Occasional Contributor III
I wonder if the license is not available when the task is initiated.  Do you have any environment variables pointing to the license server that wouldn't be set for a 'run as' on a schedule?  Is the license server or network in maintenance at that time?


http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002nt000000
0 Kudos
JohanCarlsson
Occasional Contributor
I wonder if the license is not available when the task is initiated.  Do you have any environment variables pointing to the license server that wouldn't be set for a 'run as' on a schedule?  Is the license server or network in maintenance at that time?


http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002nt000000


Thank you for your reply Alexander.

The machine that the task scheduler is running on has ArcGIS Desktop Advanced installation and the application is looking for a license for that with the following lines of code:


    public void InitializeArcObjects()
    {
      try
      {
          ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Desktop);
      }
      catch (Exception e)
      {
        throw new Exception("Could not initialize ArcObjects.", e);
      }
    }


As stated in the link you provided, this is executed before any other commands using ArcObjects.
I've been looking through the "set"-variables in the command prompt on several different machines, but I can't find any differences.
0 Kudos
AlexanderGray
Occasional Contributor III
That is the binding to the product but there is also the check-in out of the license.  Obviously that is being done correctly in the code since it does run when you launch it manually.  I was just thinking if you rely on a TNS_NAMES file to make the database connection, or a LICENSE variable to get the license server or if you ran the code during a license server black-out period you could get this problem.  If you right click on the scheduled task and run, do you get the same problem?  Are you running it as the same user?  If you have an options file on the license server, it might restrict the users allowed to check-out a license.
0 Kudos
JohanCarlsson
Occasional Contributor
The database connection is done through passing a command line to various exe-files depending on the scenario (i.e. sdelayer.exe, sdeexport.exe, sdeimport.exe) something like this:

    readonly string exportCommand = "sdeexport -o create -l $layername$,shape -f $filename$ " +
      "-i $sdeinstance$ -s $server$ -D $dbname$ -u $user$ -p $password$";


The variables surrounded by "$" are then replaced with values from a .xml file, depending on which environment the program is running on.

The same problem occurs whenever I try to run the task from the scheduler manually, no different behavior.

Could you explain to me how the license fetching is done? Does this command:

ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Desktop);


compare your local license with a license server? Do the set-variables in the commandprompt decide where this command looks for the license?

Thanks in advance.
0 Kudos
JohanCarlsson
Occasional Contributor
It seems I have solved it, it was simply a question of the settings for the task.

[ATTACH=CONFIG]27779[/ATTACH]

"Run only when user is logged in" does not require highest privileges.
"Run wether user is logged in or not" requires the "Highest privileges"-checkbox to be checked for some reason. Old versions of the program I've been working on did not require this, can't really figure out whats different.

Thank you for your time Alexander!
0 Kudos