Add the SequentialAccess flag to the executereader statement, Add order by
to the SQL statement on a predictable index, and match your select fields to
match the expected covering index. Recompute statistics of all your
indexes, drop all the temporary indexes.
If you are reading from a heap, data may not come out in the expected order
because the index that is in use orders the data in a different manner. If
you are reading from a cluster, the data will come out in the clustered
order, unless you specify an order by. Query optimizer will pick an index
that works best for the the statement, barring a good fit, it will then
create a temporary index use. The temporary indexes are not cleaned up
however and you may have to go clean them out manually.
Example
Q1 select Col1, Col2, Col3 from MyTable Order By Col1
Q2 select Col1, Col2, Col3 from MyTable Order By Col3, Col2
Q3 select Col1, Col2, Col3 from MyTable Order By Col1, Col2, Col3
Indexes:
idx1: Col1 (Unique, Not Null, Primary)
idx2: Col3, Col2 (Index Only)
Q1 Expected covering index: idx1
Q2 Expected covering index: idx2
Q3 Expected covering index: <new temporary index>
HTH
> Hi Landley
> I've tried using the Order By in the SQL query but still no joy. Infact
> the
> first record in the loop was the same record as if I hadn't used the Orber
> By
> statement. Do you know what else it could be?
Darren Kopp - 30 Sep 2005 15:13 GMT
string str_CurrentRecord =
obj_ReaderLayoutsPound.GetString(obj_ReaderLayoutsPound.GetOrdinal("Name"));
You can do something similar for all other items.