tags:

views:

119

answers:

5

I've got a query that retrieves around 10000 records from a mysql database, these records I'm reading into a .csv file.

Now after 70 records the reader hangs and doesn't do anything anymore.

Never had this in my other code until this (maybe the large data that I want to retrieve).

My code is something like this:

using (var reader = db.Retrieve(sql))
{
    while (reader.Read()) {

       //write results to my file

    }
}

The code hangs at 'while (reader.Read())'

I read this feed but no real answer was given. Or other solutions?

A: 

Have you tried this without writing this to a file?

Have you tried running this without the DataReader to make sure the query is okay?

If so, it might be worth trying a simpler query so that it returns only the one field, say, the primary key if the table's defined to have a single column primary key.

Kofi Sarfo
It is the same, already tried that
Gerbrand
+1  A: 

Did you try any of the suggestions made in the other thread?

Try looking at the SQL generated and running it in SQL Management studio and see if it runs slow there too.

Try simplifying your query and see if that makes the issue go away, then try adding back some, and see what exactly makes difference between it working and not working.

Mark Byers
it's a complex query, retrieves in total 28 columns from 7 tables
Gerbrand
I'm going to rewrite the query, I'm thinking that this is maybe the problem. But then also I doesn't take long before I'm getting my datareader back after executing the query, so maybe not the query?
Gerbrand
Receiving a datareader doesn't mean that the query is finished executing.
Mark Byers
A: 

What is the pattern of rows returned in QueryBrowser? Is mySQL batching up the returned results in a similar manner?

Jon.Stromer.Galley
A: 

Does it hang forever or eventually crash? If it crashes put it in a try catch and see what the exception is. Put the stored procedure in a try catch as well

Jay
already a try catch block around it. It hangs forever. The longest I waited was an hour.
Gerbrand
A: 

Okay I resolved the hanging in my case. My query was to complex to execute it at once. So I simplified my query and now within the minute my file is written with the results.

Gerbrand