ssis错误:调用目标引发了异常

时间:2016-06-29 14:49:09

标签: vb.net excel-vba ssis vb.net-2010 ssis-2012

ssis控制流包含一个脚本任务,它尝试打开一个excel文件,并使用workbookopen方法和saveas方法将其保存为txt文件。 它在运行pkg时显示错误

The file path is of the format \\11.111.111.1\folder1\folder2\file.xlsx


 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
       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 Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

正在使用的脚本是

Public Sub Main()



        Dim WScript As Object                                    '''= Nothing   '' with out nothing it was showing an error
        Dim oExcel As Object
        Dim oBook As Object



        Dim varoroviderFileLocation_script As String
        Dim varFileName_script As String
        Dim FullPath_script As String

        Dim v_Reversestring As String
        Dim v_ReplaceString As String




        varoroviderFileLocation_script = Dts.Variables("User::varoroviderFileLocation").Value.ToString()
        varFileName_script = Dts.Variables("User::varFileName").Value.ToString()
        FullPath_script = Dts.Variables("User::varoroviderFileLocation").Value.ToString() + "\" + Dts.Variables("User::varFileName").Value.ToString()

        MessageBox.Show(varoroviderFileLocation_script)
        MessageBox.Show(varFileName_script)
        MessageBox.Show(FullPath_script)


        oExcel = CreateObject("Excel.Application")

        oBook = oExcel.Workbooks.Open(FullPath_script)

        MessageBox.Show("FullPath_script " + FullPath_script)




        v_Reversestring = StrReverse(FullPath_script)
        v_Reversestring = v_Reversestring.Substring(5, Len(v_Reversestring) - 5)
        MessageBox.Show(v_Reversestring)
        v_Reversestring = StrReverse(v_Reversestring)



        v_ReplaceString = v_Reversestring + ".txt"

        MessageBox.Show("v_ReplaceString  " + v_ReplaceString)

        oBook.SaveAs(v_ReplaceString, -4158)




        oBook.Close(False)
        oExcel.Quit()
        WScript.Echo("Done")


        Dts.TaskResult = ScriptResults.Success
    End Sub

1 个答案:

答案 0 :(得分:0)

根据我的经验,在使用Office时,此错误是由64位运行时引起的。在配置下的项目属性中,您应将此设置为false。其他时候我看到这个错误是当引用的DLL不在GAC中或被引用的变量拼写不正确时。