【发布时间】:2011-08-02 15:20:36
【问题描述】:
我正在编写一个连接到远程服务器并读取数据等的 OPC 客户端。我正在使用 advosol 的 BGServer 类。问题是,当我在 Visual Studio 中运行程序时,添加组时出现以下错误。
“来自 HRESULT 的异常:0x80040202”
我的问题类似于 (http://stackoverflow.com/questions/5978721/opc-server-access-remotely-using-opcda-net-tools),但是,我知道 DCom 设置配置正确,因为当我通过双击我连接的 .exe 运行相同的代码,并且可以毫无问题地添加一个组。
因此,我猜测 Visual Studio 在某个奇怪的用户/组下运行,并且搞砸了 dcom 权限(主要是回调)。
编辑:代码
BGServer server;
private void Form1_Load(object sender, EventArgs e)
{
server = new BGServer(this);
server.Connect(new OPC.Common.Host() { HostName = "xp-devbox2", UserName = "OPCUser", Password = "OPCUser" }, "FactoryTalk Gateway", null, ServerConnected);
}
void ServerConnected(BGException ex, object tag)
{
if (ex != null)
{
label1.Text = ex.Message;
}
else
{
//we've connected to the server. let's start subscribing to stuff!
server.AddGroup("Tuner DataGroup", true, 1000, 0, null, null, new OnBGSrvAddGroup(GroupAdded));
}
}
private BGGroup dGroup;
void GroupAdded(BGException ex, BGGroup group, object tag)
{
if (ex != null)
{
label1.Text = ex.Message;
}
else label1.Text = "Group Added";
}
【问题讨论】:
-
所以解决这个问题的方法很明显。在项目属性的调试部分,取消选中“启用 Visual Studio 托管进程”。这摆脱了vshost,让我连接。但是,我几乎不知道这对调试有什么作用(而且关于它的 msdn 文章没有太大帮助),因此请谨慎使用。
-
另外,我不知道如何在 wpf 应用程序中关闭托管进程......所以就这样。
标签: visual-studio visual-studio-2010 dcom opc