none
Scheduled Task cannot write csv file

    Question

  • I am using Windows 7 enterprise 32 bit.

    I have a .net console application that works fine when run manually. When i try and run it as a scheduled task it runs without any errors but does not create the CSV file. i have check the permissions.
    que sera sera
    Sunday, February 14, 2010 11:21 PM

Answers

  • Hi,
    I have resolved the issue. I was calling a MS Access Jet 4 database which stored my database settings. This was causing the error. I bypassed this refence and hard coded the SQL server login info and it works great.

    I need to sort out the MS Access accessing issue though.
    que sera sera
    • Marked as answer by Wilson Jia Monday, February 15, 2010 3:31 AM
    Monday, February 15, 2010 1:48 AM

All replies

  • If the job connects to another machine you may need to add the user/ group 'logon as batch job' rights (server side). Control Panel|Admin Tools|Local Security Policy\Local Policies\User Rights Assignments
    "Log on as a batch job"

    Also mapped drives won't exist when no one is logged on so always best to use a UNC path as in;

    \\servername\sharename


    Also check the logs for clues.

    <=2003
    Scheduled Tasks|Advanced|View Log

    >=2008
    Server Manager|Diagnostics|Event Viewer|Application Logs|Microsoft|Windows|TaskScheduler

    =7
    Control Panel|Administrative Tools|Computer Management|Event Viewer|Application Logs|Microsoft|Windows|TaskScheduler



    Regards, Dave Patrick .... Microsoft Certified Professional Microsoft MVP [Windows]
    Sunday, February 14, 2010 11:43 PM
  • Hi, thianks for the prompt reply.

    I am writing the file to the c:\Users\Default\Documents\Reports folder. The console exe app is located in the same folder. It is a console application that connects to sql server and exports a few rows of transactional data to a csv file.

    The event viewer lists the following error code:

    On occassion this is the Error Value: 2147943711

    and at other times

    Log Name:      Microsoft-Windows-TaskScheduler/Operational
    Source:        Microsoft-Windows-TaskScheduler
    Date:          14/02/2010 23:34:03
    Event ID:      201
    Task Category: Action completed
    Level:         Information
    Keywords:     
    User:          PREVDECT\aarif.saiyed
    Computer:      AarifSaiyed-LT.prevdect.local
    Description:
    Task Scheduler successfully completed task "\adfadsf" , instance "{f954f334-e74e-4149-83d3-a78bb5f6f5c4}" , action "C:\Users\Default\Documents\Reports\SecureDataTransferTask.exe" with return code 0.
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="Microsoft-Windows-TaskScheduler" Guid="{DE7B24EA-73C8-4A09-985D-5BDADCFA9017}" />
        <EventID>201</EventID>
        <Version>1</Version>
        <Level>4</Level>
        <Task>201</Task>
        <Opcode>2</Opcode>
        <Keywords>0x8000000000000000</Keywords>
        <TimeCreated SystemTime="2010-02-14T23:34:03.357548400Z" />
        <EventRecordID>1390</EventRecordID>
        <Correlation ActivityID="{F954F334-E74E-4149-83D3-A78BB5F6F5C4}" />
        <Execution ProcessID="2356" ThreadID="5980" />
        <Channel>Microsoft-Windows-TaskScheduler/Operational</Channel>
        <Computer>AarifSaiyed-LT.prevdect.local</Computer>
        <Security UserID="S-1-5-21-1632134058-2691679531-345080176-1107" />
      </System>
      <EventData Name="ActionSuccess">
        <Data Name="TaskName">\adfadsf</Data>
        <Data Name="TaskInstanceId">{F954F334-E74E-4149-83D3-A78BB5F6F5C4}</Data>
        <Data Name="ActionName">C:\Users\Default\Documents\Reports\SecureDataTransferTask.exe</Data>
        <Data Name="ResultCode">0</Data>
      </EventData>
    </Event>


    que sera sera
    Monday, February 15, 2010 1:03 AM
  • Futher, I have checked the SQL server logs, there is no sql processing also happening. The task does not run but TaskScheduler shows that it has completed. I have deleted the old task and recreated a new task. this is the log of the task.

    Log Name:      Microsoft-Windows-TaskScheduler/Operational
    Source:        Microsoft-Windows-TaskScheduler
    Date:          15/02/2010 01:19:15
    Event ID:      201
    Task Category: Action completed
    Level:         Information
    Keywords:     
    User:          PREVDECT\aarif.saiyed
    Computer:      AarifSaiyed-LT.prevdect.local
    Description:
    Task Scheduler successfully completed task "\SiteSentryDataExtractor" , instance "{d623fc60-ca30-4f6a-8590-e053194a00e3}" , action "C:\Users\Default\Documents\Reports\SecureDataTransferTask.exe" with return code 0.
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="Microsoft-Windows-TaskScheduler" Guid="{DE7B24EA-73C8-4A09-985D-5BDADCFA9017}" />
        <EventID>201</EventID>
        <Version>1</Version>
        <Level>4</Level>
        <Task>201</Task>
        <Opcode>2</Opcode>
        <Keywords>0x8000000000000000</Keywords>
        <TimeCreated SystemTime="2010-02-15T01:19:15.837514300Z" />
        <EventRecordID>1510</EventRecordID>
        <Correlation ActivityID="{D623FC60-CA30-4F6A-8590-E053194A00E3}" />
        <Execution ProcessID="1164" ThreadID="2052" />
        <Channel>Microsoft-Windows-TaskScheduler/Operational</Channel>
        <Computer>AarifSaiyed-LT.prevdect.local</Computer>
        <Security UserID="S-1-5-21-1632134058-2691679531-345080176-1107" />
      </System>
      <EventData Name="ActionSuccess">
        <Data Name="TaskName">\SiteSentryDataExtractor</Data>
        <Data Name="TaskInstanceId">{D623FC60-CA30-4F6A-8590-E053194A00E3}</Data>
        <Data Name="ActionName">C:\Users\Default\Documents\Reports\SecureDataTransferTask.exe</Data>
        <Data Name="ResultCode">0</Data>
      </EventData>
    </Event>
    que sera sera
    Monday, February 15, 2010 1:19 AM
  • If the task completes but the job does not then there is something wrong with the job itself. Does the sql server allow windows authentication? Does the task account have rights to read from sql server database? From within Management Studio under SQL Server Agent\Error Logs you can look for error, severity and state codes to help determine the cause.



    Regards, Dave Patrick .... Microsoft Certified Professional Microsoft MVP [Windows]
    Monday, February 15, 2010 1:36 AM
  • Hi,
    I have resolved the issue. I was calling a MS Access Jet 4 database which stored my database settings. This was causing the error. I bypassed this refence and hard coded the SQL server login info and it works great.

    I need to sort out the MS Access accessing issue though.
    que sera sera
    • Marked as answer by Wilson Jia Monday, February 15, 2010 3:31 AM
    Monday, February 15, 2010 1:48 AM
  • Good to hear you have it working.



    Regards, Dave Patrick .... Microsoft Certified Professional Microsoft MVP [Windows]
    Monday, February 15, 2010 2:03 AM
  • Sorry for the double-post...I just re-posted this under a new thread ("Scheduled task runs, but not at system startup (unless somebody logs in)")

    Hi,
    I'm also getting failures with error 2147943711, but only when the task is started via the "At system startup" trigger (via S4U); if I click "Run" in the Task Scheduler, it runs without problems.

    I checked under Server Manager|Diagnostics|Event Viewer|Application Logs|Microsoft|Windows|TaskScheduler
    and found 2 errors just prior to the error that shows in the Scheduled Task History:

    Task Scheduler failed to log on "username" . Failure occurred in "LsaLogonUser" . User Action: Ensure the credentials for the task are correctly specified. Additional Data: Error Value: 2147943711

    Task Scheduler failed to start Task Engine "" process due to an error occurring in "LUAIsElevatedToken" . Command="taskeng.exe" . Additional Data: Error Value: 2147943711.

    I authored the task as Administrator, but want it to run as "username" (regular non-admin user with log on as batch job rights).  Whenever I make a change to the task, I am prompted for SERVER\username's password, and I'm typing it correctly.

    Here is where it gets interesting.  I added a 5 minute delay (after startup). If nobody logs on to the server within those 5 minutes after a reboot, the task fails with the error above.  If I log in immediately after reboot and check the scheduler, I see that the task is "queued", and then after the 5 minute delay, it runs correctly without me ever touching anything but "refresh"!  This is the case whether Administrator or "username" logs on.

    This sounds crazy, but it seems like "LsaLogonUser" just needs a little "nudge" (i.e. an interactive logon) before it can log on a user in the background.

    (I should really re-write my EXE as a service, but I'm not ready to take the time to do that yet...).

    Any ideas are very much appreciated.

    Thanks,

    DaveP

    Here is the task definition:

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Date>2011-03-13T16:00:17.93325</Date>
        <Author>LOGS\Administrator</Author>
      </RegistrationInfo>
      <Triggers>
        <BootTrigger>
          <Enabled>true</Enabled>
          <Delay>PT5M</Delay>
        </BootTrigger>
      </Triggers>
      <Principals>
        <Principal id="Author">
          <UserId>LOGS\username</UserId>
          <LogonType>S4U</LogonType>
          <RunLevel>HighestAvailable</RunLevel>
        </Principal>
      </Principals>
      <Settings>
        <IdleSettings>
          <Duration>PT10M</Duration>
          <WaitTimeout>PT1H</WaitTimeout>
          <StopOnIdleEnd>true</StopOnIdleEnd>
          <RestartOnIdle>false</RestartOnIdle>
        </IdleSettings>
        <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
        <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
        <AllowHardTerminate>true</AllowHardTerminate>
        <StartWhenAvailable>false</StartWhenAvailable>
        <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <Enabled>true</Enabled>
        <Hidden>false</Hidden>
        <RunOnlyIfIdle>false</RunOnlyIfIdle>
        <WakeToRun>false</WakeToRun>
        <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
        <Priority>7</Priority>
        <RestartOnFailure>
          <Interval>PT5M</Interval>
          <Count>3</Count>
        </RestartOnFailure>
      </Settings>
      <Actions Context="Author">
        <Exec>
          <Command>C:\Users\username\log\MyDotNetEXE.exe</Command>
          <WorkingDirectory>C:\Users\username\log\</WorkingDirectory>
        </Exec>
      </Actions>
    </Task>

    Thanks,

    Dave P

    Monday, March 14, 2011 7:13 PM