SSIS 脚本组件上的 WATIN - 单线程单元
您好,我需要从具有表单身份验证的站点下载文件,并使用集成服务进一步处理文本文件。
对于文件下载,我选择使用 WATIN,因此我导入了 Watin 库并编写了浏览器步骤的脚本。但是,当我尝试运行代码时,我收到一条带有此消息的异常。
CurrentThread 需要有它的 ApartmentState 设置为 ApartmentState.STA能够 自动化 Internet Explorer。
所有这一切都使用 (使用方法属性)
如果我尝试使用这行代码将其设置为 STA
System.Threading.Thread.CurrentThread.SetApartmentState(Threading.ApartmentState.STA)
我会收到此异常
错误: System.Reflection.TargetInitationException: 异常已被抛出 调用的目标。 ---> 系统.InvalidOperationException: 无法设置指定的COM 公寓状态。在 System.Threading.Thread.SetApartmentState(公寓状态 状态)
如何更改 SSIS 脚本任务以使用此单线程单元?
Hi I need to download a file from a site with forms authentication and further processing the text file with Integration Services.
For the file download I choose to use WATIN, So I imported the Watin library and scripted the browser steps. However when I try to run the code I get an Exception with this Message.
The CurrentThread needs to have it's
ApartmentState set to
ApartmentState.STA to be able to
automate Internet Explorer.
all this using the
(with the method attribute)
If I try to use this line of code to set it to STA
System.Threading.Thread.CurrentThread.SetApartmentState(Threading.ApartmentState.STA)
I get this exception
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)
How do I change the SSIS script task to use this Single-Threaded apartment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过使用 STA ApartmentState 创建另一个线程解决了这个问题。
代码是这样的:
希望这可以帮助遇到同样问题的人。
I've solved this by creating another Thread with the STA ApartmentState.
The code was like this:
Hope this helps someone with the same problem.
我发现您的解决方案对于我的类似情况非常有用,我添加了我使用的 C# 代码,以防有人需要它
,这是
BrowserWindow
类I found your solution very useful for my case that is similar, I add the C# code I used in case someone needs it
And here is the
BrowserWindow
class