我在尝试创建一个登录页面。
我获得用户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循环”之前将超时。
发布于 2019-06-01 11:34:24
根据MSDN,ExecuteReader()
将
CommandText发送到Connection并构建一个SqlDataReader。
通常,如果您在这里超时,问题在于数据库连接。查看您的代码,我认为connetionString中的连接字符串是问题所在。检查它是否真的是您要寻找的连接字符串。还检查同一连接字符串中的不可见字符。
https://stackoverflow.com/questions/56406315
复制相似问题