PRB: "Class Not Registered" Error Opening an XML Recordset (198533)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q198533

SYMPTOMS

Attempting to open an XML recordset in ADO 2.1 may generate the following error:
2147221162 - "Class not registered".
Alternatively, you may see the following error:
Run-time error '3709': The application requested an operation on an object with a reference to a closed or invalid Connection object.

CAUSE

While ADO 2.1 includes libraries that are used to generate AND persist Extensible Markup Language (XML), it does not ship the XML parser required to read the contents of the XML file and generate a recordset object.

RESOLUTION

To download the latest version of MSXML, go to . You may obtain the Microsoft XML Parser from the following resource:
  1. The XML parser is included with Microsoft Internet Explorer version 5.0. You may download or order Internet Explorer 5.0 from the following Web site:
  2. You may download the Microsoft XML Parser Redistributable, which upgrades the Microsoft XML parser from Internet Explorer 4.01 SP2 or later to the parser provided with Microsoft Internet Explorer 5. The redistributable is available for download from the following site: NOTE: Although the parser redistributable provides all of the features available from the Microsoft XML parser with Internet Explorer 5, some of the XML features available with Internet Explorer 5 will not work on Internet Explorer 4.01 SP1.
  3. The Microsoft Data Access Components versions 2.6 or later include the Microsoft XML Parser. You may download the latest version of the Microsoft Data Access Components from the following site:

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

The following code persists an ADO recordset to an XML file, then opens the XML file in a second ADO recordset.

This code uses the Pubs database that comes with SQL Server.
  1. In Visual Basic, create a new Standard EXE project. Form1 is created by default.
  2. From the Project menu, click References.
  3. From the list of References, select the Microsoft ActiveX Data Objects Library.
  4. Add two Command buttons to Form1. Command1 and Command2 are created by default.
  5. Paste the following code into the Code window for Form1.

    Note You must change User ID <username> and Password <strong password> 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.
    Private Sub Command1_Click()
    
       Dim cn As ADODB.Connection
       Dim rs As ADODB.Recordset
       
       Set cn = New ADODB.Connection
       Set rs = New ADODB.Recordset
    
       On Error Resume Next
       Kill "C:\Titles.XML"    
       On Error GoTo 0
    
       cn.Open "Provider=SQLOLEDB;Data Source=(local);" & _
               "Initial Catalog=Pubs;User ID=<user name>;Password=<strong password>;"
       
       rs.Open "select title_id, title from Titles", cn
       
      'Persist the Titles table to an XML file
       rs.Save "c:\Titles.xml", adPersistXML
       
       rs.Close
       Set rs = Nothing
       cn.Close
       Set cn = Nothing
       
    End Sub
    
    Private Sub Command2_Click()
    
        Dim rsXML As ADODB.Recordset
        Set rsXML = New ADODB.Recordset
     
        'Open the persisted recordset
        rsXML.Open "c:\Titles.xml"
        
        Do Until rsXML.EOF
           Debug.Print rsXML(0), rsXML(1)
           rsXML.MoveNext
        Loop
        
        rsXML.Close
        Set rsXML = Nothing
     
    End Sub
    
    Private Sub Form_Load()
      Command1.Caption = "&Persist"
      Command2.Caption = "&Retrieve"
    End Sub
    					
  6. Modify the connection string to connect to your server, if necessary.
  7. Select Run.
  8. Click Persist to persist the Titles table as XML.
  9. Click Retrieve to open the XML table.

    If the Microsoft XML Parser is not installed, an error occurs on rsXML.Open.

Modification Type:MajorLast Reviewed:1/26/2006
Keywords:kbprb KB198533