I'm trying to create a login page.
I get the users ID and password as parameters, and I want to access my database and compare them, but when I execute the query using ExecuteReader
, the query always times out.
The database itself is very very small, only with about 5 or 6 users so it shouldn't be timing out......
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();
The reader will timeout before entering the 'while loop'
According to MSDN, ExecuteReader()
Sends the
CommandText
to theConnection
and builds aSqlDataReader
.
Generally, if you get a timeout here, the problem is with the database connection. Looking at your code, I think the connection string in the connetionString
is the problem. Check to see if it really is the connection string you're looking for. Also check for invisible characters in the same connection string.