Reference Client (UA.-.NETStandard-master) is BadNotConnected - c#

I have a question that I already asked on the GitHub forum. Unfortunately I didn't get an answer there and I hope that you can help me here. If I do get an answer in the GitHub forum, I'll name it here. My GitHubPost can be found under the following link:
https://github.com/OPCFoundation/UA-.NETStandard/issues/1139
I will still copy the post from the GitHub forum here if the link no longer works at some point.
I downloaded the OPC UA standard project from github (https://github.com/OPCFoundation/UA-.NETStandard).
I would like to use the Reference Client there to access a Beckhoff PLC (server).
To do this, I opened the project in VS2017 and set the Reference Client as the startup project. Then I started the project with F5.
The following window opened:
Reference_Client
If I now specify the IP address and the port of my PLC (as shown above) and then click on "Connect",
the client sometimes establishes a connection to the PLC and sometimes I get the following error message:
Error_Message
In about 80% of the cases there is this error message and the client does not connect to the server.
In about 20% of the cases a connection to the server is established and I can read and write variables from the server.
I didn't change the program and it seems completely arbitrary when the connection can be established and when not.
Has anyone ever had a similar problem?
Many thanks in advance.
UPDATE 1: More detailed error message
The following screenshot shows the details of the error message. I have estimated some parts of the storage path.
Detailed_Error_Message

Please add the exception details to your post, it would be helpful to see at which place the ServiceResultException is triggered.

Thanks again for the many answers. I have been able to narrow down the cause of the problem now. I found the tip in the Github forum that you should comment out all security mechanisms:
You modify your code private static void CheckCertificateDomain(ConfiguredEndpoint endpoint) to return true always, and add AutoAcceptUntrustedCertificates true into config of the client.
This is just for developing and troubleshooting of course.
Source: Github tip
I did exactly that and then tried to connect again. I no longer receive an error message, but the operating window for OPC UA crashes. VS2017 itself does not crash, only the operating window in which the IP address can be entered and the connection can be established. When I record the network traffic with Wireshark during the crash, it can be seen that the connection (although the operating window has crashed) was successful. Data is exchanged between the client (VS2017) and the server (Beckhoff PLC).
My new approach is now to no longer use this operating window, but to write a new program. I would like to continue using the library I have used so far. The received and sent variables should then be displayed via the console.
Since this no longer has anything to do with my original question, I will make a new post for questions about this program if necessary and then add the link here.

Related

Using Wifi Direct API in legacy mode disconnects every 2 minutes

I've got a problem with my soft ap solution. When i connect a client to the ap the connection gets established and everything works fine. But I've noticed that when i set a ping to the host, it looses connection every 2 minutes and then suddenly regains connection.
This unfortunatly is unnacceptable for my solution.
I found this link: On using the WiFi Direct Api on Windows?
, which describes the same problem, but the answer isn't clear enough and i would like a code example or a more elaborate explanation.
In my solution, I use this class:
https://learn.microsoft.com/en-us/uwp/api/windows.devices.wifidirect.wifidirectadvertisementpublisher?view=winrt-19041
with legacy settings set to "enabled":
https://learn.microsoft.com/en-us/uwp/api/windows.devices.wifidirect.wifidirectlegacysettings.isenabled?view=winrt-19041
On using the WiFi Direct Api on Windows?
I have encountered exactly the same problem because I removed the following line from MS sample :
var wiFiDirectDevice = await WiFiDirectDevice.FromIdAsync(deviceInfo.Id);
It seems that if you don t create the wifiDirectDevice object, Windows will automatically disconnect the client two minutes later (although in the meantime you have been able to exchange some data).
What helped me was to compare my code with the following sample :
https://github.com/gerfen/WiFiDirectLegacyAPCSharp/blob/master/WiFiDirectHotspotManager.cs#L128
Note that I also encountered another problem when I added this line because an exception is triggered depending on the client device configuration ( see the following topic : Wi-Fi Direct UWP timeouts (Exception from HRESULT: 0x800705B4))

Reading from stream failed - mysql_native_password error

I have been facing the following error intermittently.
Authentication to host '127.0.0.1' for user 'root' using method 'mysql_native_password' failed with message: Reading from the stream has failed.
It shots up any time and I am at my wits end. I also posted a bug on MySQL bugs and solutions are not proving to be effective in any way.I hope you guys can help me out.
Here is the link to MySQL Bug for details: Never seems to go away!
Some more detail: I have a client-server system but this bug occurs on the server system(where MySQL database is installed) when a local running app on the server system tries to run a query.
I had already opened a question here but since has been dead. Just a caveat I thought that skip-name-resolve solved the issue but it seems to just have lowered the frequency. Hope someone would help me out this time around.
EDIT: The MySQL guys say that in a client server setup server may close a connection if it is unused for a long time. However, this is not what I am facing as I create a new connection everytime I want to execute a query. I made this point clear in the last comment on the MySQL Bugs.
Guys I tried this: "SslMode=None" in the connection string, but if you need SSL then read this:
http://www.voidcn.com/article/p-phfoefri-bpr.html
here is a sample connection string that works:
connectionString="Server=192.168.10.5;Database=mydata;Uid=root;Pwd=****;SslMode=None"
Hope this helps
I've been getting this error, quite frequently with Amazon's MySQL RDS instances. And most multi-AZ instances.
It would be interesting to compare notes to see if others mostly get this issue with RDS also?
Amazon is known to rely heavily on "fast" DNS changes to switch over stuff with things like ELBs. I wonder if the same thing is happening with RDS? Or some other internal AWS switching is messing up the idle connections in the pool.
This would explain why the Oracle devs can't reproduce it and don't see it as much of an issue.
Anyway I've had to just deal with it and add retry logic when opening a connection.
This issue is caused by Ssl.
Solution 1: SSL is not required. Since it is caused by SSL, we can turn off SSL by appending "SslMode=None" to the connection string.
Solution 2: SSL is required, server identity is important and needs to be verified. The server needs a internet connection to do the cert verification. Please note the crypto API doesn't update CTL for every process. The CTL is maintained at operating system level. Once you connect the server to connect and make an SSL database connection to the server, the CTL will be updated automatically. Then you may disconnect the internet connection. Note again the CTL has its expiration date and after that the Windows needs to update it again. This will occur probably after several months.
Solution 3: SSL is required but the server identity is not important. Typically SSL is only used to encrypt the network transport in this case. We can turn off CTL update:
Press Win+R to open the "Run" dialog
Type "gpedit.msc" (without quotes) and press Enter
In the "Local Group Policy Editor", expand "Computer Configuration", expand "Administrative Templates", expand "System", expand "Internet Communication Management", and then click "Internet Communication settings".
In the details panel, double-click "Turn off Automatic Root Certificates Update", clickEnabled, then click OK. This change will be effective immediatelly without restart.
http://www.voidcn.com/article/p-phfoefri-bpr.html
unfortunately, this error occurs if the application and mysql are on the same computer, if you move it to a different computer it is fine.
I tried many ways but for now there is no other solution. bug has been reported many times by others https://bugs.mysql.com/bug.php?id=76597
I had the exact same problem performing the upgrade on a windows form application. The solution I found was to change the server, because that one was in trouble. On the server that was presenting the similar situation you described had installed WordPress with MYSQL 5.6.34, on the other I did a clean install with MYSQL version 5.6.26.
I don't know if it has to do with the environment variables used. I believe it has nothing to do with Connection Timeout, if it is a property that is used only with the open connection. This error occurred in a shared environment as well as in a local installation with Maria DB. Another problem I found was that one of the selection commands that retrieved the data was having a problem in its formation not respecting the blanks:
SELECT COLUNA1, COLUNA2 FROM TABLE;
I made the change to SELECT COLUMN1, COLUMN2 FROM TABLE;
I am still testing on this solution I presented, and as of the time of posting there were no more errors.
I was getting the error
Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Reading from the stream
I solved it when I put SslMode=None in my connection string.
However, I checked that the message is different from you
Check my connection
connection.ConnectionString = "server=myadressserver;userid=myuser;password=mypassword;database=test;SslMode=None";

Tor NEWNYM is NOT working with C#

I have reviewed every question/response on stackoverflow regarding how to change the exit node IP for Tor programmatically to no avail. Every answer says that all you have to do is connect to the Tor control port and issue the "signal newnym" command, and you'll get a new exit IP. I'm using the Minimalistic Telnet Library to issue the following:
TelnetConnection tc = new TelnetConnection("127.0.0.1", 9051);
tc.WriteLine("AUTHENTICATE \"pwd\"");
tc.WriteLine("SIGNAL NEWNYM");
tc.WriteLine("QUIT");
I've added line endings, tried different Telnet libraries and direct TCP connections, and none of it works. I'm scraping a page on our development server that displays the requesting IP, and when I call this page in a loop, stopping on occasion to issue the "newnym" command, the IP address never changes. Does anybody have any idea what I'm doing wrong? Sorry to submit what appears to be a duplicate, but since none of the answers work, I don't really consider it a dupe. Thanks.
NEWNYM does not destroy existing circuits, it marks them dirty and builds new ones (among other things). Just dispose the existing TCP connections and when you build new ones you will get a new IP.
If you run a TOR relay the signal NEWNYM has no effect. it works only for TOR clients for browsing the internet. It means new identity, new circuit.
If Tor chose to ignore a signal (such as NEWNYM), this event will not be
sent. Note that some options (like ReloadTorrcOnSIGHUP) may affect the
semantics of the signals here.
Note that the HALT (SIGTERM) and SHUTDOWN (SIGINT) signals do not currently
generate any event.

Web Reference Help: No connection could be made because the target machine actively refused it

Ok, so I'm learning about ASP.NET by making a simple program to read in a user's gmail credentials and construct an email from their input into the Console, but I'm getting a new error that I was not get yesterday, and I have not changed ANY code. The error is on line 41, so I have provided that (the rest of the code is just reading input into Strings) I have disabled my firewall to no avail, and have also tried "http://localhost/Service.asmx", which doesn't work either. I've also tried restarting IIS.
I'm completely new to this subject, but the error suggests, to me, that the program is communicating with the server but is being denied by a blocked port, but I have disabled my firewall and the error persists. Any ideas? Thanks in advance!
/*40*/ Communication_Service.Service CommServiceProxy = new Communication_Service.Service();
/*41*/ Result = CommServiceProxy.SendMail(GmailAccount, Password, To, Subject, Body);
There was an error dowloading http://localhost:4932/Service.asmx. Unable to connect to the remove server. No connection could be made because the target machine actively refused it 127.0.0.1:4492
Sounds like you are running cassini (development server). The application at http://localhost:4932/ needs to be started. You probably have multiple sites and need multiple start up projects. Right click your solution and click set start up project, pick multiple, and select all your websites. On VS goto debug, run without debugging and they should all start.

How do you deal with transport-level errors in SqlConnection?

Every now and then in a high volume .NET application, you might see this exception when you try to execute a query:
System.Data.SqlClient.SqlException: A transport-level error has
occurred when sending the request to the server.
According to my research, this is something that "just happens" and not much can be done to prevent it. It does not happen as a result of a bad query, and generally cannot be duplicated. It just crops up maybe once every few days in a busy OLTP system when the TCP connection to the database goes bad for some reason.
I am forced to detect this error by parsing the exception message, and then retrying the entire operation from scratch, to include using a new connection. None of that is pretty.
Anybody have any alternate solutions?
I posted an answer on another question on another topic that might have some use here. That answer involved SMB connections, not SQL. However it was identical in that it involved a low-level transport error.
What we found was that in a heavy load situation, it was fairly easy for the remote server to time out connections at the TCP layer simply because the server was busy. Part of the reason was the defaults for how many times TCP will retransmit data on Windows weren't appropriate for our situation.
Take a look at the registry settings for tuning TCP/IP on Windows. In particular you want to look at TcpMaxDataRetransmissions and maybe TcpMaxConnectRetransmissions. These default to 5 and 2 respectively, try upping them a little bit on the client system and duplicate the load situation.
Don't go crazy! TCP doubles the timeout with each successive retransmission, so the timeout behavior for bad connections can go exponential on you if you increase these too much. As I recall upping TcpMaxDataRetransmissions to 6 or 7 solved our problem in the vast majority of cases.
This blog post by Michael Aspengren explains the error message "A transport-level error has occurred when sending the request to the server."
To answer your original question:
A more elegant way to detect this particular error, without parsing the error message, is to inspect the Number property of the SqlException.
(This actually returns the error number from the first SqlError in the Errors collection, but in your case the transport error should be the only one in the collection.)
I had the same problem albeit it was with service requests to a SQL DB.
This is what I had in my service error log:
System.Data.SqlClient.SqlException: A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
I have a C# test suite that tests a service. The service and DB were both on external servers so I thought that might be the issue. So I deployed the service and DB locally to no avail. The issue continued. The test suite isn't even a hard pressing performance test at all, so I had no idea what was happening. The same test was failing each time, but when I disabled that test, another one would fail continuously.
I tried other methods suggested on the Internet that didn't work either:
Increase the registry values of TcpMaxDataRetransmissions and TcpMaxConnectRetransmissions.
Disable the "Shared Memory" option within SQL Server Configuration Manager under "Client Protocols" and sort TCP/IP to 1st in the list.
This might occur when you are testing scalability with a large number of client connection attempts. To resolve this issue, use the regedit.exe utility to add a new DWORD value named SynAttackProtect to the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\ with value data of 00000000.
My last resort was to use the old age saying "Try and try again". So I have nested try-catch statements to ensure that if the TCP/IP connection is lost in the lower communications protocol that it does't just give up there but tries again. This is now working for me, however it's not a very elegant solution.
use Enterprise Services with transactional components
I have seen this happen in my own environment a number of times. The client application in this case is installed on many machines. Some of those machines happen to be laptops people were leaving the application open disconnecting it and then plugging it back in and attempting to use it. This will then cause the error you have mentioned.
My first point would be to look at the network and ensure that servers aren't on DHCP and renewing IP Addresses causing this error. If that isn't the case then you have to start trawlling through your event logs looking for other network related.
Unfortunately it is as stated above a network error. The main thing you can do is just monitor the connections using a tool like netmon and work back from there.
Good Luck.
You should also check hardware connectivity to the database.
Perhaps this thread will be helpful:
http://channel9.msdn.com/forums/TechOff/234271-Conenction-forcibly-closed-SQL-2005/
I'm using reliability layer around my DB commands (abstracted away in the repository interfaece). Basically that's just code that intercepts any expected exception (DbException and also InvalidOperationException, that happens to get thrown on connectivity issues), logs it, captures statistics and retries everything again.
With that reliability layer present, the service has been able to survive stress-testing gracefully (constant dead-locks, network failures etc). Production is far less hostile than that.
PS: There is more on that here (along with a simple way to define reliability with the interception DSL)
I had the same problem. I asked my network geek friends, and all said what people have replied here: Its the connection between the computer and the database server. In my case it was my Internet Service Provider, or there router that was the problem. After a Router update, the problem went away. But do you have any other drop-outs of internet connection from you're computer or server? I had...
I experienced the transport error this morning in SSMS while connected to SQL 2008 R2 Express.
I was trying to import a CSV with \r\n. I coded my row terminator for 0x0d0x0a. When I changed it to 0x0a, the error stopped. I can change it back and forth and watch it happen/not happen.
BULK INSERT #t1 FROM 'C:\123\Import123.csv' WITH
( FIRSTROW = 1, FIELDTERMINATOR = ',', ROWTERMINATOR = '0x0d0x0a' )
I suspect I am not writing my row terminator correctly because SQL parses one character at a time right while I'm trying to pass two characters.
Anyhow, this error is 4 years old now, but it may provide a bit of information for the next user.
I just wanted to post a fix here that worked for our company on new software we've installed. We were getting the following error since day 1 on the client log file: Server was unable to process request. ---> A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.) ---> The semaphore timeout period has expired.
What completely fixed the problem was to set up a link aggregate (LAG) on our switch. Our Dell FX1 server has redundant fiber lines coming out of the back of it. We did not realize that the switch they're plugged into needed to have a LAG configured on those two ports. See details here: https://docs.meraki.com/display/MS/Switch+Ports#SwitchPorts-LinkAggregation

Categories