logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 ADO Filter Bug

Posted on
2/26/2001
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
All
Product:
N/A



If you are insane enough to have more than 500 fields in your recordset, then watch out for this annoying little bug. If you attempt to set a filter on a field with an ordinal position greater than 500, ADO will fail with "Unspecified error" (our favorite kind).

This is the first bug discovered by vbRad.com that will appear as an article on the Microsoft Knowledge Base. Yoo Hoo. Yes, our lives are completely pathetic.

Below is an example of code that will demonstrate the problem. It creates a disconnected recordset with a 1000 fields (from 'f1' to 'f1000'), adds 10 records and then tries to set the filter on each one. The code will fail when trying to set a filter on 'f502' (ordinal position 501).

In my code, I've created a workaround that may or may not work for you. If your recordset is disconnected, you can recreate (basically clone) this recordset into another, but with the field that needs filtering placed first. Then you could proceed with filtering as if no bug existed. If your recordset is not disconnected, then you are on your own.

Project Creation Instructions.
  1. Createa new project.
  2. Add ADO 2.5 to the project
  3. Add a command button
Add the following to the form

Private Sub Command1_Click()
    Dim ors As New ADODB.Recordset
    Dim x As Long, i As Long
    
    For x = 1 To 1000
        ors.Fields.Append "f" & x, adInteger, 0, adFldIsNullable Or adFldUpdatable
    Next
    ors.Open
    
    For x = 1 To 1000
        ors.AddNew
        For i = 0 To ors.Fields.Count - 1
            ors.Fields(i).Value = 100
        Next
        ors.Update
    Next
	
    ors.MoveFirst
    
    For x = 1 To 1000
        'set a filter - the error will happen when x=502
        ors.Filter = "f" & x & " > 250"	
        ors.Filter = ""
    Next	
End Sub




Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By Wlodek. Posted on 6/5/2006 8:31:00 AM
Is it fixed already? What is Microsoft's kb or article number?

#2. By Author of the Article. Posted on 6/5/2006 5:37:44 PM
Here is the URL:
PRB: Error Message "Unspecified Error" When Filtering on the 501st Column in an ADO Recordset
http://support.microsoft.com/kb/290796/en-us

No, it is not fixed and will not be fixed, at least as far as I know. At the time I worked for a large multinational company so we could get microsoft to do things for us. The guy on the ADO team asked me if I wanted them to do a special build that resolved this problem, but I said no (i didn't want to saddle the application with a specific version of ADO with no upgrade path).

When I spoke to the developer, he mentioned that it would involve a pretty big architectural rewrite to fix the bug.
Regards