Re: HasRows() vs. Read() and ERROR suppression
From: James Hokes (no_way_at_noemail.com)
Date: 03/01/05
- Next message: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- Previous message: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- In reply to: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- Next in thread: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- Reply: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 1 Mar 2005 15:46:06 -0500
Scott,
I am aware of that fact at this point.
What I am really wondering, though, is what is the utility of HasRows()?
It seems worthless at first glance, but that doesn't sit right with me.
Thanks,
James Hokes
"Scott M." <s-mar@nospam.nospam> wrote in message
news:uzPKlopHFHA.2740@TK2MSFTNGP12.phx.gbl...
> That's because ExectueReader doesn't return any data, just an object that
> can look at the data.
>
> The Read method (when called for the first time) advances you to the first
> record found by executing the commandText. If you don't call Read, you
> are never attempting to process any data.
>
>
> "James Hokes" <no_way@noemail.com> wrote in message
> news:e%23BZFgpHFHA.3588@TK2MSFTNGP14.phx.gbl...
>> Scott,
>>
>> Specifically, it is a type conversion error, Level 16, State 1.
>>
>> Here's the info:
>> Server: Msg 241, Level 16, State 1, Procedure selADOTest, Line 7
>> Syntax error converting datetime from character string.
>>
>> However, as I stated in the post, the error does not fire if you
>> pre-emptively check .HasRows() and avoid calling .Read().
>> I would have thought the exception would be thrown upon .ExecuteReader()
>> on the Command object, but it does not. Apparently, for some reason you
>> MUST call .Read() on the SqlDataReader, or you don't get the exception.
>>
>> Baffling.
>>
>> I posted a repro script (both T-SQL and VB.Net) in the other part of the
>> thread where I'm conversing with Marina.
>>
>> Thanks,
>> James Hokes
>>
>>
>> "Scott M." <s-mar@nospam.nospam> wrote in message
>> news:eUyqMWoHFHA.1860@TK2MSFTNGP15.phx.gbl...
>>> What type of SQL exception are you running into?
>>>
>>> Have you tried:
>>>
>>> Try
>>> rdr = cmd.ExecuteReader
>>>
>>> If rdr.HasRows Then
>>> While rdr.Read
>>> 'Process row..
>>> Loop
>>> End If
>>> Catch ex as Exception
>>> 'examine exception
>>> End Try
>>>
>>> "James Hokes" <no_way@noemail.com> wrote in message
>>> news:%23bxEyRoHFHA.4060@TK2MSFTNGP14.phx.gbl...
>>>> Hi All,
>>>>
>>>> We're using the 1.1. Framework against SQL Server 2000, and are having
>>>> a strange issue where we don't get errors back from the stored
>>>> procedure, i.e. the exception never gets thrown.
>>>>
>>>>
>>>> We use SqlDataReader objects to stream stored procedure results back
>>>> when we have a smallrowsets.
>>>>
>>>> Normally, our code looks like so:
>>>>
>>>> '...set up connection and command...
>>>> rdr = cmd.ExecuteReader
>>>>
>>>> While rdr.Read
>>>> 'Process row...
>>>> Loop
>>>>
>>>> 'et cetera...
>>>>
>>>> In this case, the exception fires normally.
>>>>
>>>>
>>>> However, one of our developers tried:
>>>>
>>>> If rdr.HasRows Then
>>>> While rdr.Read
>>>> 'Process row..
>>>> Loop
>>>> End If
>>>>
>>>> This results in the total suppression of SQL Server errors that
>>>> occurred in the stored procedure.
>>>>
>>>> Why does this occur?
>>>> Of what use is HasRows() if it doesn't throw the exceptions that are
>>>> apparently waiting in the SqlDataReader stream?
>>>>
>>>> Are there any other "scenarios" we should be aware of which would
>>>> suppress the SQL Exceptions? This is scary.
>>>>
>>>>
>>>> Thanks,
>>>> James Hokes
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
- Next message: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- Previous message: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- In reply to: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- Next in thread: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- Reply: Scott M.: "Re: HasRows() vs. Read() and ERROR suppression"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|