Microsoft Knowledge Base Email Alertz

(311313) - 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...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 311313 - Last Review: October 12, 2005 - Revision: 2.3

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

This article was previously published under Q311313

On This Page

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 (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.

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.

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
Keywords: 
kbhotfixserver kbqfe kbado260fix kbbug kbfix kbmdac260fix kbqfe KB311313
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate