PRB: E_FAIL Returned from Prepare() When SQL Statement Contains a Parameter in a Subquery (235053)
The information in this article applies to:
- Microsoft OLE DB Provider for SQL Server 7.01, when used with:
- Microsoft Data Access Components 2.0
- Microsoft Data Access Components 2.1
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.6
- Microsoft Data Access Components 2.7
- Microsoft OLE DB Provider for SQL Server 7.0, when used with:
- Microsoft Data Access Components 2.0
- Microsoft Data Access Components 2.1
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.6
- Microsoft Data Access Components 2.7
This article was previously published under Q235053 SYMPTOMS
Using the OLE DB Provider for SQL Server and calling the ATL CCommand::Prepare() function, or ICommandPrepare::Prepare(), returns E_FAIL with the following error description:
Syntax error or access violation.
The SQL Server OLE DB Provider that ships with MDAC 2.7 returns the following improved error message:
Parameter Information cannot be derived from SQL statements with sub-select queries. Set parameter information before preparing command.
CAUSE
The SQL command text for the OLE DB Command object contains a parameter in a subquery. For example, the following SQL statement causes the error:
SELECT * FROM Table1 WHERE field2 IN <BR/>
(SELECT field1 FROM Table2 where field1 > ?)
The Microsoft OLE DB provider for SQL Server cannot derive parameter information from subqueries.
RESOLUTION
You must call CCommand::SetParameterInfo() or ICommandWithParameters::SetParameterInfo() before calling Prepare().
Please see the MORE INFORMATION section of this article for sample code that uses the ATL OLE DB consumer templates and demonstrates calling SetParameterInfo().
STATUS
This behavior is by design.
Modification Type: | Minor | Last Reviewed: | 11/3/2003 |
---|
Keywords: | kbConsumer kbDatabase kbDTL kbprb KB235053 |
---|
|