I trying to connect an OPC server with C# in VS2013.
Here is the most important two lines:
OpcServer Srv = new OpcServer();
int rtc = Srv.Connect(...);
The facts which I know:
I'm runing this code another PC, not on localhost (in OPC server)
I know the IP address of OPC server
I know the URI for the OPC: opcda://Helmholz.OPC.S7.DA/{8C5FBBB7-0A62-4fcb-99CC-BEE0D4B0B6DE}
But, I don't know how can I define this information in the Srv.Connect command.
If you are using OPC NET API, you probably want to use something like:
opcda://1.2.3.4/Helmholz.OPC.S7.DA/{8C5FBBB7-0A62-4fcb-99CC-BEE0D4B0B6DE}
I wrote an article about "OPC URLs": http://www.opclabs.com/resources/developer-blog/1086-a-partial-story-of-opc-urls?showall=&limitstart=
Related
Why i failed to connect to a free cloud mysql DB using C# connector from Nuget in my work office PC while i can connect just fine to the same server using mysql CLI tool?
The message i get when i fail to connect is "Connect Timeout expired.".
I also tried on my PC at home and i can connect just fine using exactly the same C# code.
Mysql CLI tool also work from home.
Could it be a firewall or other security measure in my work company network? Why it does not block the mysql CLI tool?
I also tried with a localhost mysql (using mysqld on port 51255) at work.
I managed to connect using mysql CLI tool but got the same error as before on c# code.
EDIT1 - Code included
EDIT2 - localhost attempt
private async Task<string> ConnectDB()
{
MySqlConnectionStringBuilder dbinfo = new MySqlConnectionStringBuilder
{
Server = "******",
Port = ****,
Database = "*****",
UserID = "*****",
Password = "*****",
};
using(MySqlConnection connection = new MySqlConnection(dbinfo.ConnectionString))
{
try
{
await connection.OpenAsync();
}
catch (MySqlException error)
{
message = error.Message;
}
if (connection.State == ConnectionState.Open)
{
message = "Success!";
}
}
return message;
}
We see the same C# code works at home, but not at the office. Therefore it's not the code; it must be something with the environment at the office. But you can connect at the office via the command line tools, so it's also not the corporate firewall, which would have a very hard time telling the the difference between the two.
What's left is something on the local PC at work. The local OS firewall and antivirus software both come to mind, and of the two the antivirus software sounds more suspect to me. One other option is DNS, where the DNS service at the office is resolving the host name for the database differently. But without more info this is just a guess. I suggest adding a lot more logging; right now we don't even know the full error message.
As an additional note, it's not common and considered very poor practice to directly expose a database to the internet. Additionally, the application should be well-connected to the database. The definition for "well-connected" has changed over the years, but "public internet" is not going to count. Typically, if you most host the database in another location you will have a web API endpoint in front of the database, where the server for this API can be in the same location as the DB and therefore well-connected.
I was provide a link of OPC server: http://192.168.2.5:54354 and was asked for read an Item value.
I am new to OPC and I assumed that my server is OPC XML-DA but when I try the sample code, it work.
But when I replace my server URL and Item name, it not work, the server address seem to be missing some part
var client = new EasyDAClient();
DAVtqResult[] vtqResults = client.ReadMultipleItems(
new ServerDescriptor { UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx" },
new DAItemDescriptor[]
{
"Dynamic/Analog Types/Double",
"Dynamic/Analog Types/Double[]",
"Dynamic/Analog Types/Int",
"SomeUnknownItem"
});
This one work but did not work with my Server URL: http://192.168.2.5:54354
I am not sure what /XmlDaSampleServer/Service.asmx means but I am able to connect to my sever using https://www.kassl.de/opc/explorer.shtml
Are you sure the server is XML-DA? Very few servers use this protocol in my experience. It is usually OPC DA (OPC Classic) or OPC UA.
Is there any security on the server like username and password?
From my experience, you need to be able to establish a connection with an existing client before writing any code. There could be a network or firewall issue. It appears that the server is on your local network. Can you connect to it with the Kassl client from the same server? OPC DA relies on the COM/DCOM components for communication that tend to have many issues with remote connections and firewalls.
Try the following steps:
Ping the server and make sure it replies.
Install an OPC client like Kassl or Kepware on the same Windows machine as the server and see if it can connect.
If it can, disable firewall, antivirus, etc. and see if you can connect remotely.
Check if there are any port-forwarding that needs to be done. You may want to use Wireshark to see what is happening with the data.
I am able to have c# (client) and python (server) talk to each other by using a simple request-reply. However, I want my web application built on c# asp.net to be stable and need more clients and servers, so I tried connecting c# and python using the Router-Dealer Proxy with python.
I tried running the proxy python script first, then running c# (client), then python (server). However, when I run the python (server), it gives me an "Address in use" error message.
Am I running them in a wrong order OR is there something wrong with the proxy python script (shown below)?
5602 = c# client
5603 = python server
def main():
context = zmq.Context()
# Socket facing clients
frontend = context.socket(zmq.ROUTER)
frontend.bind("tcp://*:5602")
# Socket facing services
backend = context.socket(zmq.DEALER)
backend.bind("tcp://*:5603")
zmq.proxy(frontend, backend)
# We never get hereā¦
frontend.close()
backend.close()
context.term()
if __name__ == "__main__":
main()
I'm assuming your servers use bind, so the proxy should connect to them rather than also using bind.
Note: in zeromq the order of application startup doesn't matter so you can tell your proxy to connect to a server that doesn't yet exist, when the server is started the connection will be made.
My c# console app runs on an different machine than my SQL Server 2014. I use ado.net to connect to it. How can I detect if the sql server automatically reboots after installing windows updates? On my client application I use SystemEvents_SessionEnding but this does not help me.
I read about connection resiliency, but this seems also not to solve this problem.
Is there a specific ado.net event I can capture? Creating an app on the server sending UDP is not my prefered solution, aswell I dont want to use ping etc.
I'm really looking for something like an event to react on.
e.g. the notification services: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlnotificationinfo(v=vs.110).aspx
Thanks!
If you want to see if the server is down or not you can use Ping Class.
using System.Net.NetworkInformation;
var ping = new Ping();
var reply = ping.Send("SqlServerIP");
if (reply.Status == IPStatus.Success)
{
//server is available
}
else
{
//server is down
}
I am trying to control/run JAMS from a C# application. Most of the examples I have checked only connect to localhost, but I am trying to connect to a remote server through my program to use JAMSShr assembly.
I current am doing the following, which works great:
JAMS.Server js = JAMS.Server.GetServer("localhost");
I'm trying this to connect to the remote server:
JAMS.Server js = JAMS.Server.GetServer("JAMS_SCHED.PEER1.Company.COM");
I have username and password setup in JAMS.
Make sure their is an entry in host file to resolve your server name to IP address.
Also make sure API versions are compatible with version of JAMS server you are using.They are not very compatible.