The An existing connection was forcibly closed by the remote host error occurs when trying to establish a socket connection between the client and server. This error is usually triggered if the remote side closes the connection.
The error can occur if you are sending malformed data to the third-party application or if it senses the data to be malformed. In other cases, it can be an unstable link between the client and server, a glitch in the third-party app or system resource issues.
Here is how to fix the existing connection was forcibly closed by the remote host socket exception error in your computer.
How do I fix an existing connection was forcibly closed by the remote host error?
1. Enable Strong Cryptography
- Press Windows Key + R to open Run.
- Type regedit and hit enter. This will open the Registry Editor.
- In Registry Editor, navigate to the following location:
- Locate the ScsUseStrongCrypto
- If the ScsUseStrongCrypto value is not present, navigate to the following path instead:
- Double-click on the SchUseStrongCrypto
- In the Value data field enter 1 and click OK.
- Close Registry Editor and try to establish the connection again and check if the issue is resolved.
The aforementioned error will occur if Cryptography is disabled in Registry Editor for a machine which will also disable the usage of TLS 1.2. Try enabling the property in Registry Editor to see if that fixes the issue.
If you are unable to enable strong cryptography through Registry Editor, follow the steps below to do it via PowerShell.
Use PowerShell to enable strong cryptography
- Open PowerShell.
- Enter the following command one by one and hit enter to execute:
Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWordSet-ItemProperty -Path
‘HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWord
- Once executed, reboot your computer and check for any improvements.
2. Update .NET framework
- Go to Microsoft Download centre.
- Download Microsoft .NET framework.
- Run the downloaded file to execute it.
- Follow-on screen instructions to install the latest of .NET framework.
- Once installed, reboot the computer and check if the error is resolved.
3. Force use TLS 1.2
- Open the global.asax file. You can find it by navigating to the root of the project.
- Select View Code from the list.
- Scroll down to Application_Start method.
- Add the following line of code under the method:
if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Tls12) == false)
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
- Save the changes and run the code to see if the error is resolved.
Adding the above-mentioned lines can help you resolve the issue if the application that is triggering the error is configured to use TLS 1.1 by forcing TLS 1.2 usage.
4. Edit the .Context.cs file
- Locate the .context.cs file. You can find it under .edmx > context.tt file.
- Open the .context.cs file.
- Add the following line to your construction.
this.Configuration.ProxyCreationEnabled = false; //add the following line to your code
- Save the changes and check if the error is resolved.
Adding the above line of codes to your constructor will help you resolve the issue if you are using Entity Framework.
5. Diagnose the error with Wireshark
The troubleshooting steps in the article above are user-specific and if that did not help you fix the problem, try to diagnose the issue by yourself.
The existing connection was forcibly closed by the remote host usually occurs when the remote side closes the connection. If you are working with a third-party application, the error can occur due to one of the following reasons.
- The remote site is detecting malformed data being sent from your connection and closing the connection.
- The application is experiencing a service outage.
- Your request may have triggered a glitch in the third-party app causing it to malfunction.
- You or the remote site may have exhausted its system resources.
To diagnose the issue, fire up Wireshark. This will help you to analyze the behaviour and narrow down the problem.
You can filter the Wireshark dump by IP address and port number. Start by looking at the end of the stream and follow the trail back to see where and what went wrong.
Knowing what is causing the ‘an existing connection was forcibly closed by the remote host’ error is the first step towards fixing the problem. While we have listed some common solutions that have helped other users fix the error, the issue can vary depending on the user.
Leave a Reply