c# - 错误无法从传输连接读取数据。连接被对端重置。赛马林

标签 c# .net xamarin xamarin.forms xamarin.android

当我暂停我的应用程序并在一段时间后恢复时,我收到此错误消息:

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.

所以,你应该检查你的网络连接

欲了解更多信息,

看看类似问题herehere

IOException

关于c# - 错误无法从传输连接读取数据。连接被对端重置。赛马林,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51236025/

相关文章:

c# - 当 Gacutil.exe 拒绝服务时如何从 GAC 中删除 dll

android - 使用可本地化的格式字符串进行数据绑定(bind)

c# - 使用 LINQ 列出 XML

c# - 如何传递 WebAPI Controller 数据,以便发布的模型可以在绑定(bind)/反序列化或验证时访问

c# - 当第二个线程都调用 WaitOne() 并由 AutoResetEvent 释放时,为什么第二个线程在第一个线程之前被释放?

c# - mac用户名和密码怎么找

c# - 将音频从一台设备流式传输到另一台设备

C# 泛型和 void 的特例

c# - 压缩和解压缩源数据给出的结果与源数据不同

.net - 在 Azure 云中部署不安全代码