An existing connection was forcibly closed by the remote host

后端 未结 12 1844
说谎
说谎 2020-11-22 09:26

I am working with a commercial application which is throwing a SocketException with the message,

An existing connection was forcibly closed by the rem

相关标签:
12条回答
  • 2020-11-22 09:55

    Simple solution for this common annoying issue:

    Just go to your ".context.cs" file (located under ".context.tt" which located under your "*.edmx" file).

    Then, add this line to your constructor:

    public DBEntities() 
            : base("name=DBEntities") 
        { 
            this.Configuration.ProxyCreationEnabled = false; // ADD THIS LINE !
        }
    

    hope this is helpful.

    0 讨论(0)
  • 2020-11-22 09:58

    This is not a bug in your code. It is coming from .Net's Socket implementation. If you use the overloaded implementation of EndReceive as below you will not get this exception.

        SocketError errorCode;
        int nBytesRec = socket.EndReceive(ar, out errorCode);
        if (errorCode != SocketError.Success)
        {
            nBytesRec = 0;
        }
    
    0 讨论(0)
  • 2020-11-22 10:03

    Using TLS 1.2 solved this error.
    You can force your application using TLS 1.2 with this (make sure to execute it before calling your service):

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 
    

    Another solution :
    Enable strong cryptography in your local machine or server in order to use TLS1.2 because by default it is disabled so only TLS1.0 is used.
    To enable strong cryptography , execute these commande in PowerShell with admin privileges :

    Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
    Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord 
    

    You need to reboot your computer for these changes to take effect.

    0 讨论(0)
  • 2020-11-22 10:03

    This error occurred in my application with the CIP-protocol whenever I didn't Send or received data in less than 10s.

    This was caused by the use of the forward open method. You can avoid this by working with an other method, or to install an update rate of less the 10s that maintain your forward-open-connection.

    0 讨论(0)
  • 2020-11-22 10:07

    I had this issue when i tried to connect to postgresql while i'm using microsoft sutdio for mssql :)

    0 讨论(0)
  • 2020-11-22 10:08

    This generally means that the remote side closed the connection (usually by sending a TCP/IP RST packet). If you're working with a third-party application, the likely causes are:

    • You are sending malformed data to the application (which could include sending an HTTPS request to an HTTP server)
    • The network link between the client and server is going down for some reason
    • You have triggered a bug in the third-party application that caused it to crash
    • The third-party application has exhausted system resources

    It's likely that the first case is what's happening.

    You can fire up Wireshark to see exactly what is happening on the wire to narrow down the problem.

    Without more specific information, it's unlikely that anyone here can really help you much.

    0 讨论(0)
提交回复
热议问题