DCom/OPC 应用程序在 Visual Studio 中运行时无法连接,但 .exe 连接完美

发布于 2024-11-27 15:54:20 字数 1296 浏览 2 评论 0原文

我正在编写一个连接到远程服务器并读取数据等的 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";
    }

I'm writing an OPC client that connects to a remote server and reads data etc. I am using advosol's BGServer class. The issue is, when I run the program in visual studio I get the following error on adding a group.

"Exception from HRESULT: 0x80040202"

My problem is similar to (http://stackoverflow.com/questions/5978721/opc-server-access-remotely-using-opcda-net-tools), however, I know the DCom settings are configured correctly because when I run the same code by double clicking the .exe I connect and can add a group with no problems.

Therefore I'm guessing that visual studio is running under some strange user/group, and screws up the dcom permissions (mainly with callbacks).

edit: code

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";
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半暖夏伤 2024-12-04 15:54:20

您是否使用免注册 COM 与 OPC 通信?当您使用“Visual Studio 托管进程”时,您创建的 do reg-free COM 的任何外部“.exe.manifest”文件都不会被带入 vshost.exe 进程的清单中。

Are you using reg-free COM to communicate with the OPC? When you use the "Visual Studio Hosting Process" any external ".exe.manifest" files that you create the do reg-free COM will not be carried into the manifest of the vshost.exe process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文