daa daa
daa daa

Reputation: 141

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);
       //.........

    }
}

Upvotes: 6

Views: 43628

Answers (1)

Anas Alweish
Anas Alweish

Reputation: 3026

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

Upvotes: 4

Related Questions