FIX: ADO Returns No Resultset for Prepared Parameterized Query Involving CHAR Data with SQLOLEDB (311313)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.01
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 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: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.

MORE INFORMATION

Steps to Reproduce Behavior

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

    Note You must change the User ID= <username> value and the Password =<strong 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 = "Provider=SQLOLEDB.1;integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs;Data Source=mySQL7"
    
      ' Connection string to a SQL Server 2000.
      ' strCn = "Provider=SQLOLEDB.1;User ID=<user name>;Password=<strong password>;Initial Catalog=pubs;Data Source=mySQL2000"
    
      cn.ConnectionString = strCn
      cn.Open strCn
      cmdPrep1.ActiveConnection = cn
      cmdPrep1.CommandType = adCmdText
      cmdPrep1.Prepared = True
      cmdPrep1.CommandText = "SELECT * FROM authors WHERE zip LIKE ? ORDER BY au_id"
    
      Set prm1 = cmdPrep1.CreateParameter(, adChar, adParamInput, 2, "9%")
    
      ' Set this property to repro against SQL Server 2000. By default, this is TRUE.
      ' cmdPrep1.Properties("Defer Prepare") = False
    
      cmdPrep1.Parameters.Append prm1
      rs.CursorLocation = adUseClient
      rs.CursorType = adOpenStatic
      rs.Open cmdPrep1
      MsgBox "Number rows = " & rs.RecordCount
      rs.Close
      cn.Close
    					
  4. Save the project and then run it. Although you would expect to see a record count of 16, no rows are obtained.

Modification Type:MinorLast Reviewed:10/12/2005
Keywords:kbHotfixServer kbQFE kbADO260fix kbbug kbfix kbMDAC260fix kbQFE KB311313 kbAudDeveloper