workbook.open fails when program is not called directly

R

Rfuu

I am having trouble getting a proccess to run unattended using Excel 2003 on
Windows Server 2008. When I run the code through Visual Studio or run the
..exe through either windows explorere or the cmd prompt it works exactly as
intended but when I try to run it as a windows scheduled task or SQL job the
workbook.open line fails with error code hresult: 0x800a03ec. The code below
is a scaled down version cut from the rest of the proccess but behaves the
same way.


Imports Microsoft.Office.Interop.Excel

Module Module1
Private excelApplication As Application = Nothing

Sub Main()
Dim sFileSpec As String

sFileSpec = "E:\Temp\test.xls"
EventLog.WriteEntry("OpenFileTest", "before try")
Try
excelApplication = New Application
EventLog.WriteEntry("OpenFileTest", "before open " & sFileSpec)
excelApplication.Workbooks.Open(sFileSpec)
EventLog.WriteEntry("OpenFileTest", "before close")
excelApplication.Quit()
Catch ex As Exception
EventLog.WriteEntry("OpenExcelFile Error", ex.ToString)
Finally
If Not excelApplication Is Nothing Then
excelApplication.Quit()
excelApplication = Nothing
End If
End Try

End Sub

End Module
 
D

David Lloyd

Rfuu:

This could be a DCOM issue related to the permissions of the user account
the SQL job (running under the permissions of the SQL Server Agent service
account) or the task scheduler account. is using. Either account must have
permissions to perform the automation, something that is present normally
when you run it from Windows Explorer or a command prompt.

Please see the link below for how to edit the DCOM security settings.

http://www.ureader.com/msg/10941513.aspx

Best regards,

David Lloyd
Lemington Consulting
http://lemingtonit.com
 
J

JMiguez

Rfuu,

Make sure your external libraries are compatible with the version of
windows you're trying to run.
Furthermore make sure you have all of them in the executable folder.
One thing to try is to copy all files within the debug folder into
your windows server executable folder and see if libraries are
compatible. If not, you will have to download the correct set of
libraries for win 2008

Hope that solves the problem.

Cheers.

Juan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top