Re: why is sqldatareader so slow ?
- From: "Octavio Hernandez" <dotnet@xxxxxxxxxxxx>
- Date: Fri, 12 Aug 2005 10:28:56 +0200
Marc,
a) How long does it take to execute the query with the SQL Server tools? If
there it takes a long time, maybe tou should use the SL Profiler or the
Index Tuning Wizard, maybe you lack some indices that could make the query
go faster...
b) The C# code looks fine to me, and I have a lot of similar code in several
apps (well, I don't know how complex you query is, but mine are not simple
for sure), and obtaining a result set of this size is very fast.
c) I suppose in real life you want to do something different than count the
resulting rows; if that is the case, you'd better change the query to SELECT
COUNT(*) ... and put the burden on the server.
Regards - Octavio
"marc hugon" <sorry@xxxxxxxxxx> escribió en el mensaje
news:bmjof1hdoae8v1o4m97omem2hdequ4831b@xxxxxxxxxx
> Hello
>
> I'm working on a batch program (command line utility), and I'm having
> speed problems to read a lot of data from a database.
> At first I thought it was what i was doing with the data that was slow
> (and I can work on that), but I've encoutered another problem.
>
> let's have a look at my current source code (removed lot of things) :
>
> SqlConnection myConnection = new SqlConnection("Sql connect string");
> myConnection.Open();
> string mySelectQuery = "something a little fancy";
> Console.WriteLine("Launch request "+DateTime.Now.ToLongTimeString());
> myCommand = new SqlCommand(mySelectQuery,myConnection);
> myCommand.CommandTimeout=600; //it may be long, so...
> SqlDataReader myReader;
> myReader = myCommand.ExecuteReader();
> Console.WriteLine("Data work "+DateTime.Now.ToLongTimeString());
> int counter = 0;
> while (myReader.Read())
> {
> counter++;
> }
> Console.WriteLine(counter.ToString());
> myReader.Close();
> myConnection.Close();
> Console.WriteLine("End "+DateTime.Now.ToLongTimeString());
>
> and now : what I have on my console when executing this beauty :
> Launch request 09:07:47
> Data work 09:07:57
> 17742
> End 09:09:37
>
> 1:40 minutes to read 17 742 rows of data ??????
> how is this possible ??
> how to make it work faster ?
> any help appreciated
>
> by the way, the sql request is returning 4 rows of the following types
> : sqlsingle (real) (x2), string (varchar(7)), int (int(2))
> I've tried using a dataset, it was a little slower.
> one last information : the sql server is running on my development
> computer, so no connexion problem between the command line and the
> server....
>
> Any idea, comment, critic, more than welcome :)
>
> (by the way, I have other functions dealing with more than 500000
> lines of data, the complete process takes more than 3 hours, that's
> why I MUST find something faster)
>
> Marc
.
- Follow-Ups:
- Re: why is sqldatareader so slow ?
- From: marc hugon
- Re: why is sqldatareader so slow ?
- References:
- why is sqldatareader so slow ?
- From: marc hugon
- why is sqldatareader so slow ?
- Prev by Date: Re: How to run specific thread on specific CPU
- Next by Date: Re: When they press ENTER?
- Previous by thread: why is sqldatareader so slow ?
- Next by thread: Re: why is sqldatareader so slow ?
- Index(es):
Relevant Pages
|