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.....
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");
}
}
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);
//.........
}
}
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.)
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With