当我暂停我的应用程序并在一段时间后恢复时,我收到此错误消息:
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.
经过多次搜索,我找到了这个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.
所以,你应该检查你的网络连接
欲了解更多信息,
关于c# - 错误无法从传输连接读取数据。连接被对端重置。赛马林,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51236025/