M
Mark
Hi...
I came to a company with great volumes of legacy code, and I found an odd
pattern.
They use SqlDataReader for a lot of queries, but the reader is rather
unfriendly with GetOrdinal(); if the column isn't there, it throws an
exception, rather than returning -1 or some other friendlier value.
In several places in the code, they've simply put a try/catch around the
GetOrdinal() to make it less nasty, but given the expense of exceptions, that
seems pretty onerous.
Would SqlDataReader.GetSchemaTable().Columns.IndexOf ("name"); be cheaper?
I don't know if GetSchemaTable() is returning the DataTable it has
internally, or if it has to cobble one together from scratch, which would cut
into the time.
As an aside, what's the reason SqlDataReader.GetOrdinal() is so unfriendly?
I mean, I suppose it requires the reader users to have more explicit
knowledge of their queries, but as I've found, people can still come up with
rather expensive alternatives to keep vague about the details of their data.
Thanks
Mark
I came to a company with great volumes of legacy code, and I found an odd
pattern.
They use SqlDataReader for a lot of queries, but the reader is rather
unfriendly with GetOrdinal(); if the column isn't there, it throws an
exception, rather than returning -1 or some other friendlier value.
In several places in the code, they've simply put a try/catch around the
GetOrdinal() to make it less nasty, but given the expense of exceptions, that
seems pretty onerous.
Would SqlDataReader.GetSchemaTable().Columns.IndexOf ("name"); be cheaper?
I don't know if GetSchemaTable() is returning the DataTable it has
internally, or if it has to cobble one together from scratch, which would cut
into the time.
As an aside, what's the reason SqlDataReader.GetOrdinal() is so unfriendly?
I mean, I suppose it requires the reader users to have more explicit
knowledge of their queries, but as I've found, people can still come up with
rather expensive alternatives to keep vague about the details of their data.
Thanks
Mark