Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Unable to read data from transport connection. Connection reset by peer. Xamarin

When I pause my application and then resume after a while, I get this error message:

System.IO.IOException: Unable to read data from the transport connection. Connection reset by peer ---> system.net.sockets.....

I've assigned a class which defines all my objects inside my activity example:

public class Connection: Activity
{
    protected SqlConnection con;
    protected string MyIp;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        var prefs = Application.Context.GetSharedPreferences("Preferences", FileCreationMode.Private);
        MyIp = prefs.GetString("IpAdress", null);

        con = new SqlConnection("Data Source = " + MyIp + "; Initial Catalog = WiOrder; user id = admin; password = 1234;Connection Timeout=5");

    }
}

Here is how I call this class inside activity:

public class Main : Connection
{
    protected override void OnCreate(Bundle savedInstanceState)
    {

        base.OnCreate(savedInstanceState);
       //Rest of my code
       con.Open();
       SqlCommand cmd = new SqlCommand (//query,con);
       //.........

    }
}
like image 736
daa daa Avatar asked Jul 08 '18 21:07

daa daa


People also ask

Why can't I read data from the transport connection?

Unable to read data from the transport connection: Connection reset by peer. This error usually means that the target machine is running, but the service that you're trying to connect to is not available. (Either it stopped, crashed, or is busy with another request.)

What are the reasons for System Io IOException readresponse () failed?

System.IO.IOException Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host ReadResponse () failed: The server did not return a complete response for this request. Server returned 0 bytes.

What does connection reset by peer error mean?

This error is generated when the OS receives notification of TCP Reset (RST) from the remote peer. Connection reset by peer means the TCP stream was abnormally closed from the other end. A TCP RST was received and the connection is now closed.


1 Answers

I faced the same issue and I was getting this exception (sometimes) when trying to connect to the server.

Unable to read data from the transport connection: Connection reset by peer.

After many searches, I found this answer

Quote from the answer

This error usually means that the target machine is running, but the service that you're trying to connect to is not available. (Either it stopped, crashed, or is busy with another request.)

In English: The connection to the machine (remote host/server/PC that the service runs at) was made but since the service was not available on that machine, the machine didn't know what to do with the request.

So, you should check your network connection

For more information,

Take a look at the similar questions here and here

IOException

like image 81
Anas Alweish Avatar answered Oct 01 '22 03:10

Anas Alweish