I wrote a SSIS script task where I use VB code to read data from a database using ODBC and then dynamically create an excel spreadsheet using the Microsoft.Office.Interop.Excel object. The code then saves the spreadsheet to a directory folder on the sql server. The server OS is 32 bit Windows Server 2008 Standard, and SQL Database is SQL 2005.
When I execute the package in the SQL Server Business Development Studio on the server, it works perfectly and the package writes the spreadsheet to the folder on the server without any problem.
I then save the package on the server using "Server Storage" and I set up a scheduled job to run the package. Every time the SQL Agent runs this job , I get this error
Executed as user: XECC\Administrator. Microsoft (R) SQL Server Execute Package Utility Version 9.00.4035.00 for 32-bit Copyright (C) Microsoft Corp 1984-2005. All rights reserved. Started: 8:49:42 AM Error: 2010-03-19 08:49:46.69 Code: 0x00000002 Source: create_spreadsheet Description: The script threw an exception: Exception from HRESULT: 0x800A03EC End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 8:49:42 AM Finished: 8:49:46 AM Elapsed: 3.884 seconds. The package execution failed. The step failed.
I have created many other packages before using script tasks and I have used the sql agent to execute them, and I never have had a problem before. I should note that none of my previous packages used the Microsoft.Office.Interop.Excel object to create an Excel spreadsheet, so maybe this is some how causing the problem.
I created the job step for executing the SSIS package using SQL Server Authentication since I saved the package to the server using "Server Storage" with the same login account.
I did a test and I commented out the statement in the VB script that actually saves the workbook to the folder on the server and when I executed the job in the SQL Agent with this statement commented out, the job worked fine without an error. When I remove the comment and try to write the spreadsheet to the folder, I get the that same error .
Here is my Vb code
sql = "select * from logs order by "
cmd = New OdbcCommand(sql, cn)
rs = cmd.ExecuteReader
Dim app As New Microsoft.Office.Interop.Excel.Application
Dim WB As Microsoft.Office.Interop.Excel.Workbook
app.Visible = False
app.UserControl = False
app.DisplayAlerts = False
WB = app.Workbooks.Add
WB.Application.Selection.NumberFormat = "0"
Do While rs.Read = True
k = CType(rs("0"), Integer)
For i = 0 To 170
If IsDBNull(rs.Item(i)) = True Then GoTo finish
j = i + 1
WB.Application.Cells._Default(k, j) = rs.Item(i)
WB.Sheets(1).Name = "logs"
When I comment this statement out, the SQL Agent job works fine.
WB = Nothing
app = Nothing
Dts.TaskResult = Dts.Results.Success
I am wondering if because Excel is involved now is there something in security that is causing the job to fail?
I am wondering if because Excel is involved now in this package is there something in security that is causing the job to fail?