ssis - SSIS 脚本组件上的 WATIN - 单线程单元

标签 ssis watin sql-server-2008-r2

您好,我需要从具有表单例份验证的站点下载文件,并使用集成服务进一步处理该文本文件。

对于文件下载,我选择使用 WATIN,因此我导入了 Watin 库并编写了浏览器步骤的脚本。但是,当我尝试运行代码时,我收到一 strip 有此消息的异常。

The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer.

所有这一切都使用 (使用方法属性)

如果我尝试使用这行代码将其设置为 STA

System.Threading.Thread.CurrentThread.SetApartmentState(Threading.ApartmentState.STA)

我得到这个异常

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Failed to set the specified COM apartment state. at System.Threading.Thread.SetApartmentState(ApartmentState state)

如何更改 SSIS 脚本任务以使用此单线程单元?

最佳答案

我通过使用 STA ApartmentState 创建另一个线程解决了这个问题。

代码是这样的:

Private threadDelegate As ParameterizedThreadStart
Private filesdir As String

<STAThread()> _
Public Sub Main()
    Try
        threadDelegate = New ParameterizedThreadStart(AddressOf Me.DoSomething)
        StartBrowserRoutine(threadDelegate)
        Dts.TaskResult = ScriptResults.Success
    Catch
        Dts.TaskResult = ScriptResults.Failure
    End Try
End Sub

Private Sub StartBrowserRoutine(ByVal threadRoutine As ParameterizedThreadStart)
    Dim dialogThread As Thread = New Thread(threadRoutine)
    dialogThread.TrySetApartmentState(ApartmentState.STA)
    dialogThread.Start(Nothing)
    dialogThread.Join(System.Threading.Timeout.Infinite)
End Sub

Private Sub DoSomething()
    'Do Something
End Sub

希望这可以帮助遇到同样问题的人。

关于ssis - SSIS 脚本组件上的 WATIN - 单线程单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5503079/

相关文章:

sql - 如何向文件 : input field in the Foreach loop container SSIS 添加多个文件扩展名

asp.net - 如何为 Web 测试做模拟?

c# - Watin 不会手动触发 .change() 事件

sql-server-2008-r2 - 使用表变量比临时表更快

deployment - 如何配置SSIS 2012项目在不同的环境配置下运行?

SSIS ‘Data Flow Task’ 平面文件目标中没有记录

.net - WatiN System.IO.FileNotFoundException Interop.SHDocVw

sql - 使用内联查询或连接从另一个表中获取数据?

java - SQLServer express R2 的 JDBC 连接 Url

sql-server - SSIS连接管理器不存储SQL密码