简体   繁体   中英

C# Console App with Excel Interop hangs as a scheduled task on Windows scheduler/ActiveBatch

I have a C# application that opens an Excel file on a network drive, reads data and writes to a database. I can run it manually from a batch file, but it isn't working when I run the batch file from Windows Scheduler or ActiveBatch. I don't actually get an error - the job just hangs when it tries to open the Excel workbook (not when it opens the application).

I am running under the same user credentials both when I run manually and from a scheduler. I'm using .NET 3.5 on Windows Server 2003 Enterprise SP2 with Office 2007.

I've tried the "Ogawa Hack" described here , and I've tried using a level of indirection by writing another batch file that would be run by the scheduler and would call the original file. Neither worked.

Any other ideas I can try?

Since your application will probably run on a server, I would recommend not using Excel Interop for this task. There are free .NET libraries available, which don't require Excel to be installed. For the older Excel <= 2003 format look here

http://jexcelapi.sourceforge.net/

(in the files section you will find a .NET port of this Java lib). For the newer XML based formats, you can use this one:

http://excelpackage.codeplex.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM