Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I try retrive a data from a MySQL database using the ExecuteReader() command i receive a timeout error like this :

TimeoutException was unhandled : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Can any one state a possible reason for this exception.

The troublesome fragment of code is as under :

Dim connectionst As String = connectionstring   'String concealed 
 Dim querystring As String = "SELECT dat1 FROM mydb WHERE dat2 = '" + txtbox.Text + "';"
Dim commandgive As New MySqlCommand(querystring)
         Dim commandgive As New MySqlCommand(querystring)
        commandgive.Connection = connection
        Dim dataread As MySqlDataReader
        dataread = commandgive.ExecuteReader() 'Problematic code.


The line commented a problematic code is where vb shows me a timeout exception.

Why is this so ?
Updated 18-Apr-13 15:13pm
Bernhard Hiller 19-Apr-13 2:52am    
Where does the MySQL sever run - on the same machine as your code, or on a different machine?
compuknow 19-Apr-13 3:59am    
The application runs on the same machine where the MySQL server runs. In my connection string , i have mentioned localhost.

1 solution

Well, either your connection string is wrong (great job keeping an important piece of information hidden!) and you're not really connecting to the box you think you are or your MySQL server didn't respond with the query results in the default time allowed to execute the command (usually 30 seconds).

That's about all anyone can tell you given the lack of information provided.
Share this answer
compuknow 18-Apr-13 22:10pm    
sir , what information is lacking ? I could have provided.

It would not be right to reveal a connection string in a Public domain as it contains security information.

The connection string is right , because it worked when i was inserting data into this same database , the connection string used for insertion is being used here for extraction.

The query string must be right because , i know there exists those columns which are being reffered in that query string.

Could you suggest any other method for receiving data other than ExecuteReader() ?
Dave Kreskowiak 19-Apr-13 8:22am    
It has nothing to do with the syntax of your query. I already told you what the two possibilites are for this error. Have a nice day.
compuknow 19-Apr-13 10:55am    
The query string executes when executed through the MySQL Command Line Client.

ExecuteReader() must return perfectly because the query hits well through the dedicated command line client of MySQL.

The connection string works well with ExecuteNonQuery() Command , but not with ExecuteReader() command.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900