Hi
I have a script task which opens a csv file using excel and save it as Excel File. I chose this method after a long struggle to use it as flat file source (too many issues I had). It jsut become so much reliable to work with after converting it as Excel.
The issue I have is when I run the script as a job, it fails. It works fine in BID.
1. I am using Proxy (admin) account to register it as a job.
2. in Execution options, 'Use 32 bit' runtime is ticked
I have other SSIS packages scheduled as jobs and they are all running fine (including 32 bit runtime).
It's just this script this causing me a lot of headaches.
The error message I got is
System.Reflection.TargetInvocationException:
Exception has been thrown by the
targetof an invocation.---> System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Excel cannot access the file 'G:\ReadingEggFTP\AU\20130619\readingeggs_3pau_school_marketing_customer_list_20130619.csv'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook. at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename,
Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
at ST_a340a727a31942219e1e112705df885a.vbproj.ScriptMain.Main() --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&
sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo
culture, String[] namedParams) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
• The file name or path does not exist - Yes it does. Otherwise I couldn't do it in BID.
• The file is being used by another program - I am just running the script only (Testing by each object)
• The workbook you are trying to save has the same name as a currently open workbook - It is the same name but the extension is differe
nt). Again, it works in BIDS.
The following is the script code (I got it from a web)
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.Office.Interop.Excel
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Public Sub Main()
Dim excel As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim FiletoOpen As String
' Dim ws As Microsoft.Office.Interop.Excel.Worksheet
FiletoOpen = Dts.Variables("User::FTPAUFileDestinationPath").Value.ToString + "\" + Dts.Variables("User::FTPFileAUDownloaded").Value.ToString
wb = excel.Workbooks.Open(FiletoOpen)
'' ws = wb.Worksheets(1)
wb.SaveAs((Dts.Variables("User::AUUploadFile").Value.ToString), FileFormat:=Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8)
wb.Close()
excel.Quit()
Runtime.InteropServices.Marshal.ReleaseComObject(excel)
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
Thanks!