【发布时间】:2019-06-01 21:05:02
【问题描述】:
我正在尝试创建一个登录页面。
我将用户 ID 和密码作为参数,我想访问我的数据库并比较它们,但是当我使用 ExecuteReader 执行查询时,查询总是超时。
数据库本身非常非常小,只有大约 5 或 6 个用户,所以应该不会超时......
SqlConnection cnn = null;
string connectionString = null;
connectionString = @"Data Source=DESKTOP-A5GR284\SQLEXPRESS;Initial Catalog=Chat_DB;Integrated Security=True";
cnn = new SqlConnection(connectionString);
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Users", cnn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine("{0}", reader.GetString(1));
}
reader.NextResult();
}
cnn.Close();
阅读器在进入'while循环'之前会超时
【问题讨论】:
-
尝试使用调试器看看发生了什么。此外,请查看 SQL 部分的
using,以便它为您自动关闭您的连接(它实现了IDisposeable- 在这里:stackoverflow.com/questions/16985876/…)
标签: c# sql-server executereader