FIX: OpenSchema Method Generates Error 3251 (195487)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.01

This article was previously published under Q195487

SYMPTOMS

Using server-side cursors to open a recordset with OpenSchema, such as "Set rs = Connection.OpenSchema" generates error 3251:
Application-defined or object-defined error.

CAUSE

Using the ActiveX Data Objects (ADO) OpenSchema method uses the IDBSchemaRowset interface to provide advanced schema information. This interface uses the GetRowset method to return a schema rowset. Currently, properties are not passed to the IDBSchemaRowset::GetRowset() when using a server-side cursor. This includes the IConnectionPointContainer property that is necessary for supporting notification (events). This results in ADO not hooking in the notification.

RESOLUTION

Open the connection on the client-side. For example:
   Set Connection.CursorLocation = adUseClient
				
This way the client engine passes the IConnectionPointContainer property, and ADO can hook in the notification.

STATUS

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

This problem has been fixed in MDAC 2.1 Service Pack 2 (SP2) and later versions of MDAC.

MORE INFORMATION

Steps to Reproduce Behavior

Use the following steps to reproduce this behavior using Visual Basic code:
  1. Start a new Visual Basic project. Form1 is created by default.
  2. Add a command button (Command1) to Form1. Change the name property to cmdOpenSchema.
  3. Add the Microsoft ActiveX Data Objects 2.0 Library as a Reference.
  4. Paste the following code in the General Declaration of Form1.

    Note You must change UID <username> and PWD <strong password> to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation on the database.
          Option Explicit
             Dim WithEvents rs_Events As ADODB.Recordset
    
          Private Sub cmdOpenSchema_Click()
    
             Dim cn As New ADODB.Connection
    
             On Error GoTo ErrHandler
    
             Set cn = New ADODB.Connection
    
            ' Uncomment the following line to workaround the problem:
            ' cn.CursorLocation = adUseClient
    
            ' Open connection
            cn.Open "Provider=MSDASQL;DSN=pubs;UID=<user name>;PWD=<strong password>;Database=pubs;"
    
            ' Error 3251 occurs at the following line.
            Set rs_Events = cn.OpenSchema(adSchemaTables)
    
            ' As a test: Print all table names and types in your database.
            Do Until rs_Events.EOF
               Debug.Print "Table name: " & rs_Events!TABLE_NAME & _
                  vbCr & "Table type: " & rs_Events!TABLE_TYPE & vbCr
              rs_Events.MoveNext
           Loop
    
          ' Clean up objects.
             rs_Events.Close
             cn.Close
             Set rs_Events = Nothing
             Set cn = Nothing
    
          Exit Sub
    
          ErrHandler:
    
              MsgBox Err.Number &amp; ": " &amp; Err.Description
    
          End Sub
    					
  5. Run the program. Notice that when the Cursorlocation property is set to adUseClient that all the information prints properly to the Immediate Window.

Modification Type:MinorLast Reviewed:3/14/2005
Keywords:kbADO210sp2fix kbADO250Fix kbADO260fix kbBug kbDatabase kbfix kbMDAC260fix kbmdac270fix kbMDACNoSweep KB195487