FIX: "Unhandled Exception" Error Message When You Use ExecuteReader Method with CommandBehavior.SingleRow (313547)
The information in this article applies to:
- Microsoft ADO.NET (included with the .NET Framework)
This article was previously published under Q313547 This article refers to the following Microsoft .NET
Framework Class Library namespaces:
- System.Data
- System.Data.OleDb
SYMPTOMS If you try to return an empty DataReader object by using the ExecuteReader method of an OleDbCommand object with a CommandBehavior value of SingleRow, you receive the following error message or similar:
An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll This
occurs when you use the Microsoft OLE DB Provider for SQL Server with the OLE
DB .NET Managed Provider. If you catch the exception, the message of
the exception states: Object or data matching the name,
range, or selection criteria was not found within the scope of this operation.
You expect the DataReader to be returned without an error. In addition, you expect the Read method of the DataReader to return False if no rows are found.
RESOLUTION When you use the OLE DB Provider for SQL Server, do not use
a CommandBehavior value of SingleRow if you do not return records with the ExecuteReader method of OleDBCommand.
Alternately, use the SQL Server .NET Managed Provider.
The error does not occur when you use the SQL Server .NET Managed Provider,
even if you use a CommandBehavior value of SingleRow. STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
This bug was corrected in Microsoft ADO.NET
(included with the .NET Framework 1.1).
REFERENCES For more information, visit the following Microsoft Web
site:
Modification Type: | Major | Last Reviewed: | 4/9/2003 |
---|
Keywords: | kbfix kbbug kbDatabase kbpending kbSystemData KB313547 |
---|
|