Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Script Task to Refresh Excel Workbook fails when scheduled as a Job.

$
0
0

Hi ,

I wrote below code in a Script task  to refresh an Excel work book .

The code and the task works fine when I run it manually from BIDS in Windows server 2008 R2.

But, It is getting failed when I schedule it as job and is giving below error.

Date,Source,Severity,Step ID,Server,Job Name,Step Name,Notifications,Message,Duration,Sql Severity,Sql Message ID,Operator Emailed,Operator Net sent,Operator Paged,Retries Attempted
01/29/2013 08:06:17,Reportrefresh,Error,0,PHX04,Reportrefresh,(Job outcome),,The job failed.  The Job was invoked by User bi_mjullidimudi.  The last step to run was step 1 (LZReportRefresh).,00:00:06,0,0,,,,0
01/29/2013 08:06:17,LZReportrefresh,Error,1,PHX04,LZReportrefresh,LZReportRefresh,,Executed as user: CRED\SQLAGENT. Microsoft (R) SQL Server Execute Package Utility  Version 10.50.2500.0 for 64-bit  Copyright (C) Microsoft Corporation 2010. All rights reserved.    Started:  8:06:17 AM  Error: 2013-01-29 08:06:23.15     Code: 0x00000001     Source: ReportRefresh      Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x800A03EC): General ODBC Error     at Microsoft.Office.Interop.Excel.WorkbookClass.RefreshAll()     at ST_39a334f3244a4b1998adb06688f49f98.csproj.ScriptMain.ExcelRefresh(String Filename)     --- End of inner exception stack trace ---     at System.RuntimeMethodHandle._InvokeMethodFast(Object target<c/> Object[] arguments<c/> SignatureStruct& sig<c/> MethodAttributes methodAttributes<c/> RuntimeTypeHandle typeOwner)     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj<c/> BindingFlags invokeAttr<c/> Binder binder<c/> Object[] parameters<c/> CultureInfo culture<c/> Boolean skipVisibilityChecks)    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj<c/> BindingFlags invokeAttr<c/> Binder binder<c/> Object[] parameters<c/> CultureInfo culture)     at System.RuntimeType.InvokeMember(String name<c/> BindingFlags bindingFlags<c/> Binder binder<c/> Object target<c/> Object[] providedArgs<c/> ParameterModifier[] modifiers<c/> CultureInfo culture<c/> String[] namedParams)     at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript() End Error  DTExec: The package execution returned DTSER_FAILURE (1).  Started:  8:06:17 AM  Finished: 8:06:23 AM  Elapsed:  5.772 seconds.  The package execution failed.  The step failed.,00:00:06,0,0,,,,0

I have Microsoft Office 2010 standard and Microsoft Office 2010 primary Interop Assemblies installed on Windows Server 2008 R2.

I am able to schedule other SSIS packages properly with the same account. But , not the one with Scrip task which has code to refresh an Excel file.Please help me.

Here is the code that I am using inside script task.

 public void Main()
        {
            // TODO: Add your code here
            Dts.TaskResult = (int)ScriptResults.Success;
           // ExcelRefresh(Dts.Variables["ReportFile"].Value.ToString());
           ExcelRefresh(@"C:\\SSIS\\LegalZoomsales\\SalesReport.xlsx");
          
           
        }
        private void ExcelRefresh(string Filename)
        {
            object NullValue = System.Reflection.Missing.Value;
           

            //Open Excel application.
            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
            excelApp.DisplayAlerts = false;

            //Open Excel Workbook.
            Microsoft.Office.Interop.Excel.Workbook Workbook = excelApp.Workbooks.Open(
               Filename, NullValue, NullValue, NullValue, NullValue,
               NullValue, NullValue, NullValue, NullValue, NullValue,
               NullValue, NullValue, NullValue, NullValue, NullValue);

            //Refresh the data in Excel workbook.
            Workbook.RefreshAll();
           

            // Save the workbook.
            Workbook.Save();
            
            //Close the workbook
            Workbook.Close(false, Filename, null);

            //Close the Excel application

            excelApp.Quit();
            Workbook = null;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);


        }
    }

I really appreciate any help.

Thank You,

Madhu



Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>