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";
}
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.
User contributions licensed under CC BY-SA 3.0