vb.net SSIS(VS 2012) VB 脚本组件问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23063807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SSIS(VS 2012) Issue with VB script compounent
提问by user3532499
I am facing an issue in SSIS. I just upgraded my project from VS 2005 to VS 2012 and all of my packages were upgraded at the same time. All of them work well, except the one where I use script task to check if a file exists in a folder before working on the data from the flat file.
我在 SSIS 中遇到了一个问题。我刚刚将我的项目从 VS 2005 升级到 VS 2012,并且我的所有软件包都同时升级。所有这些都运行良好,除了我使用脚本任务在处理平面文件中的数据之前检查文件夹中是否存在文件的那个。
Since this upgrade, when I launch package with this script task:
自从这次升级后,当我用这个脚本任务启动包时:
- If the file is present in the folder, it works well.
- If the file is missing, it crashes just after the "else" clause on : Dts.Events.FireError(0, "FlatFile", "Error loading '" + filepath + "', flat file not found", String.Empty, 0) with the following error message:
- 如果该文件存在于文件夹中,则它运行良好。
- 如果文件丢失,它会在“else”子句之后崩溃:Dts.Events.FireError(0, "FlatFile", "Error loading '" + filepath + "', flat file not found", String.Empty, 0) 带有以下错误消息:
Exception has been thrown by the target of an invocation. 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()**
调用的目标已抛出异常。在 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, CultureInfoculture) 在 System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] 修饰符,CultureInfo 文化, String[] namedParams) 在 Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()**
And then it crashes on the end sub with the following error message:
然后它在最后的 sub 上崩溃,并显示以下错误消息:
Exception has been thrown by the target of an invocation. 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()**
调用的目标已抛出异常。在 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, CultureInfoculture) 在 System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] 修饰符,CultureInfo 文化, String[] namedParams) 在 Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()**
If I disable the Dts.Events.FireError I still got the same error on the end sub
如果我禁用 Dts.Events.FireError 我仍然在结束子上遇到相同的错误
Here is my code(Visual Basic 2012):
这是我的代码(Visual Basic 2012):
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
<Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Public Sub Main()
Dim filepath As String
filepath = "\localhost\MYPATH"
If My.Computer.FileSystem.FileExists(filepath) Then
If FileLen(filepath) > 0 Then
Dts.TaskResult = ScriptResults.Success
Else
Dts.Events.FireError(0, "FlatFile", "Error loading '" + filepath + "', flat file not found", String.Empty, 0)
Dts.TaskResult = ScriptResults.Failure
End If
Else
Dts.Events.FireError(0, "FlatFile", "Error loading '" + filepath + "', flat file not found", String.Empty, 0)
Dts.TaskResult = ScriptResults.Failure
End If
End Sub
End Class
结束班
回答by billinkc
I expect the issue is that you are not providing a return status for the subroutine
我希望问题是您没有为子程序提供返回状态
If My.Computer.FileSystem.FileExists(filepath) And FileLen(filepath) > 0 Then
Dts.TaskResult = ScriptResults.Success
Else
Dts.Events.FireError(0, "FlatFile", "Error loading '" + filepath + "', flat file not found", String.Empty, 0)
Dts.TaskResult = ScriptResults.Failure
End If
Edit
编辑
Expectations are one thing but actually debugging is another. I set a break point at the step where you assigned filepath. The root problem is that the FileLenoperation is trying to check the size of a file that doesn't exist. Here you can see that a FileNotFoundException is thrown and unhandled.
期望是一回事,但实际调试是另一回事。我在您分配文件路径的步骤设置了一个断点。根本问题是该FileLen操作试图检查不存在的文件的大小。在这里你可以看到一个 FileNotFoundException 被抛出并且没有被处理。



