Re: why is sqldatareader so slow ?



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


.



Relevant Pages

  • Re: SQL Query Performance
    ... Execute the query and see which is faster. ... I support the Professional Association of SQL Server and it's community of SQL Server professionals. ... > I want to select Fleet_Id and Fleet_Name from fleet table> Where the current user has privilege. ...
    (microsoft.public.sqlserver.programming)
  • Re: CONTAINS performance
    ... That said, and with the query plan, I can start to give you more ... relational join in the context of the free-text optimization, ... SQL Server tables. ...
    (microsoft.public.sqlserver.fulltext)
  • Re: SQL 2000 manual start job sort order
    ... As you might know, without ORDER BY, SQL Server is free to optimize and execute a query in any way ... then the optimizer has to ...
    (microsoft.public.sqlserver.server)
  • Re: Indexing Service, Openquery and sp_executesql
    ... SQL Server version and sp are you running? ... > data from the indexing service catalog when pasted into ... > query analyzer, but failed when put against sp_executesql ... I would choose Microsoft Indexing ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Problem using Access or Query Designer to run queries in SQL Serve
    ... >or Query Designer within Enterprise Manager, it works and I get data back. ... >ODBC Call Failed [ODBC SQL Server Driver] Timeout Expirederror in Access ... >[ODBC SQL Server Driver] Timeout Expired ...
    (microsoft.public.sqlserver.odbc)