如何解决 ASP.NET Web API 中的连接超时过期问题?

2024-02-01

我使用 ASP.NET Web API 从数据库中检索大量数据作为 json 数据列表,但在浏览器控制台中收到此错误:

Failed to load resource: the server responded with a status of 500 ()

以及浏览器页面中的此错误:

"InnerException": {
       "Message": "An error has occurred.",
       "ExceptionMessage": "The wait operation timed out",
       "ExceptionType": "System.ComponentModel.Win32Exception",
       "StackTrace": null
}

我该如何解决这个问题?

这是我的代码:

SqlConnection con = new SqlConnection(@"server = ...; database = ...; Integrated Security=false;
                    user id = ...; password = ...; Max Pool Size=2097151;");

public IHttpActionResult Getusers()
{
        SqlDataAdapter da = new SqlDataAdapter("select * from usersnotifications", con); 
        DataTable dt = new DataTable();

        da.Fill(dt);

        if (dt.Rows.Count > 0)
        {
            return Ok(dt);
        }
        else
        {
            return Ok("No data found ...");
        }
}
  • Note:如果我检索很少的数据,此代码可以工作。

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何解决 ASP.NET Web API 中的连接超时过期问题? 的相关文章

随机推荐