The information in this article applies to:
SYMPTOMSWith SQL Server's Quoted_Identifier set to Off, you may receive the following error: This error occurs when you are using client-side cursors with the Microsoft OLE DB Provider for SQL Server (SQLOLEDB). The error occurs on an ActiveX Data Objects (ADO) recordset's Update method, and may occur on an AddNew method. CAUSE
With ADO client-side cursors, when you invoke an ADO recordset's AddNew or
Update method, the OLE DB Provider prepares a SQL statement to send to SQL
Server.
The preceding would be prepared similar to the following:
Note that the table name is in quotes, "titles", and that each field name
is in quotes, "title", "title_id", and so on.
If SQL Server's Quoted_Identifier option is set to Off, SQL Server will not recognize table names and field names enclosed in quotes. The error "Syntax error near 'tablename'" occurs. RESOLUTIONFollowing are two workarounds that allow you to set the quoted_identifier off and update records using ADO recordsets.
-or- For example, before opening an ADO Connection object named cn, use the following syntax:
NOTE: Examples of both workarounds are shown in the MORE INFORMATION section.
STATUSThis behavior is by design. MORE INFORMATIONADO and the underlying OLE DB Provider are not aware of the SQL Server setting for the quoted_identifier, as set by the Transact SQL (T-SQL) statements:
The OLE DB Provider for SQL Server automatically quotes identifiers to ensure that if the identifier contains a special character, it will be quoted, as required by SQL Server. Note that the identifier does not have to actually contain a special character. It is only the possibility that causes the OLE DB Provider to quote the identifier. The OLE DB Provider for SQL Server does not have a property to explicitly specify that identifiers should or should not be quoted. You can configure the OLE DB provider for ODBC to prepare SQL statements with or without quotes around identifiers. It uses the ODBC driver setting for QuotedID to determine whether to quote identifiers. For this reason, you may include the "QuotedID=Yes" or "QuotedID=No" option in the ODBC connect string, or select/deselect "Use ANSI Quoted Identifiers" in a DSN setup. Note that, by default, "QuotedID=Yes", instructing the ODBC to quote identifiers. When you use ADO server-side cursors, cursors open on the server. The OLE DB Provider prepares the T-SQL sp_cursoropen, sp_cursorfetch, and related server-side cursor statements, instead of action queries. The ADO Connection object's "Quoted Identifier Sensitivity" property shows the configuration a Provider uses to quote identifiers. The "Quoted Identifier Sensitivity" property is read-only, and only available at run- time after the Connection object has been opened. The "Quoted Identifier Sensitivity" property is only available for certain Providers, including the SQL Server and ODBC Providers. Since the property is read-only, you cannot use the "Quoted Identifier Sensitivity" property to configure a Provider to quote or not quote identifiers. The ADO Connection object's read-only "Quoted Identifier Sensitivity" property will be as follows:
Steps to Reproduce BehaviorNOTE: In the following code examples, substitute your server's name for servername in the connection strings.This example uses the Pubs database that comes with SQL Server.
Examples of WorkaroundsUsing the OLE DB Provider for ODBC Drivers (MSDASQL)You must use the SQL Server ODBC driver 2.65.0240 that ships with SQL Server 6.5 Service Pack 2, or a later driver.Modify the connection string in the preceding example to the following:
Using Server-Side CursorsModify the cn.CursorLocation in the preceding example to the following:
If you are using the SQL Server SQLTrace program, you may examine the T-SQL
sp_cursor statements that the OLE DB Provider creates.
REFERENCES
SQL Server Books Online; search on: "quoted_identifier."
Q135533 INF: Differences in SQL Behavior Between ODBC and ISQLFor additional information on the Microsoft ActiveX Data Objects, please visit the following Web site: http://www.microsoft.com/data/ado/ Additional query words:
Keywords : kbADO150 kbADO200 kbOLEDB kbSQLServ kbGrpVBDB kbGrpMDAC kbDSupport kbMDAC210SP2 |
Last Reviewed: November 16, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |