Microsoft KB Archive/311313

= FIX: ADO Returns No Resultset for Prepared Parameterized Query Involving CHAR Data with SQLOLEDB =

Article ID: 311313

Article Last Modified on 10/12/2005

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.01
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft OLE DB Provider for SQL Server 2000 2000.80.194
 * Microsoft OLE DB Provider for SQL Server 7.0
 * Microsoft OLE DB Provider for SQL Server 7.01

-



This article was previously published under Q311313



SYMPTOMS
ActiveX Data Objects (ADO) may return no data with the SQLOLEDB provided under the following conditions:
 * The Prepared property on the command object is set to TRUE.
 * The query has a parameterized LIKE clause.
 * The column included with the LIKE clause is defined as CHAR (and not as VARCHAR) at the back end.
 * The parameter value has fewer characters than the back-end column size.
 * You are connecting to either a Microsoft SQL Server 7.0 or SQL Server 2000 database. If it is a SQL Server 2000 database, the Defer Prepare property is set to FALSE on the command object.

This problem occurs with the versions of ADO that are listed in the beginning of this article.



RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft Data Access Components service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

The English version of this has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.    Date           Version         Size        File name 18-OCT-2001   2.62.8018.0     528,656     Msado15.dll

WORKAROUND
You can work around this problem by changing the data type of the column involved in the LIKE clause from CHAR to VARCHAR.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a Standard EXE project using Microsoft Visual Basic 6.0. Add a Project Reference to the Microsoft ActiveX Data Objects 2.6 Library. Add a CommandButton to the main Form.  Double-click the Command button. Paste the following code in the Command1_Click event handler:

Note You must change the User ID= value and the Password = value to the correct values before you run this code. Make sure that User ID has the appropriate permissions to perform this operation on the database. Dim cn As New ADODB.Connection Dim cmdPrep1 As New ADODB.Command Dim rs As New ADODB.Recordset Dim prm1 As New ADODB.Parameter Dim strCn As String

' Connection string to a SQL Server 7.0. strCn = &quot;Provider=SQLOLEDB.1;integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs;Data Source=mySQL7&quot;

' Connection string to a SQL Server 2000. ' strCn = &quot;Provider=SQLOLEDB.1;User ID= ;Password= ;Initial Catalog=pubs;Data Source=mySQL2000&quot;

cn.ConnectionString = strCn cn.Open strCn cmdPrep1.ActiveConnection = cn cmdPrep1.CommandType = adCmdText cmdPrep1.Prepared = True cmdPrep1.CommandText = &quot;SELECT * FROM authors WHERE zip LIKE ? ORDER BY au_id&quot;

Set prm1 = cmdPrep1.CreateParameter(, adChar, adParamInput, 2, &quot;9%&quot;)

' Set this property to repro against SQL Server 2000. By default, this is TRUE. ' cmdPrep1.Properties(&quot;Defer Prepare&quot;) = False

cmdPrep1.Parameters.Append prm1 rs.CursorLocation = adUseClient rs.CursorType = adOpenStatic rs.Open cmdPrep1 MsgBox &quot;Number rows = &quot; & rs.RecordCount rs.Close cn.Close  Save the project and then run it. Although you would expect to see a record count of 16, no rows are obtained.

Additional query words: ADO no result parameterized prepare SQLOLEDB CHAR defer LIKE

Keywords: kbbug kbfix kbado260fix kbqfe kbmdac260fix kbhotfixserver KB311313

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.