PRB: Load From Stream Fails When Specifying MSPersist Provider

ID: Q245485


The information in this article applies to:
  • Microsoft Data Access Components version 2.5
  • Microsoft Visual Basic Enterprise Edition for Windows, version 6.0


SYMPTOMS

When you try to specify a connection string to use the persist provider to open from a valid ADO stream object, you receive the following error message:

Run-time error '3001': Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.


CAUSE

When a stream is used to open a recordset, there should be no parameters specified other than the source parameter of the open method.


RESOLUTION

Remove any parameter other than the source of the recordset as follows:


rs.Open stm           ' no other parameters should be specified 

If you want to reconnect to a connection to allow updating, you can associate an active connection after opening the Recordset.


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Visual Basic project. Form1 is created by default.


  2. Add a Command button (Command1) to Form1.


  3. Add a Reference to Microsoft ActiveX Data Objects 2.5 Library.


  4. Paste the following code in the general declaration section of Form1:


  5. 
    Option Explicit
    Dim rs As ADODB.Recordset
    Dim stm As ADODB.Stream
    
    Private Sub Persist_To_XML_File()
    
        Set rs = New Recordset
    
        If Dir("C:\foo.xml") <> "" Then
            Kill "C:\foo.xml"
        End If
        
        rs.Open "SELECT * FROM authors", "DSN=pubs;uid=sa;pwd=;", _
                 adOpenStatic, adLockReadOnly, adCmdText
        rs.Save "C:\foo.xml", adPersistXML
    
        MsgBox ("XML file was created successfully!")
    
        rs.Close
        Set rs = Nothing
    
    End Sub
    
    
    Private Sub Command1_Click()
        
        ' Create an XML file via the Authors table in Pubs
        Persist_To_XML_File
        
        ' Populate the recordset by opening a Stream object
        MsgBox ("Now.. will populate the recordset by opening a Stream object")
        Load_RS_From_Stream
        MsgBox ("Process was done successfully!")
        
    End Sub
    
    Sub Load_RS_From_Stream()
        
       Set rs = New Recordset
       Set stm = New ADODB.Stream
       
       stm.Open         ' Open a stream object
       stm.Charset = "iso-8859-1"   ' character set strings code for ANSI, ASCII
       'Load a Stream object from the XML file
       stm.LoadFromFile "C:\foo.xml"
       
       ' Uncommenting the connection string in the following line generates error 3001
       rs.Open stm ', "Provider=MsPersist"
    
       While Not rs.EOF             'Get first field for all records in the recordset
           Debug.Print rs(0)
           rs.MoveNext
       Wend
       
       stm.Close
       Set stm = Nothing
       
       rs.Close
       Set rs = Nothing
    
    End Sub 
  6. Run the code to notice the behavior.



REFERENCES



For more information on the recordset persistence, please refer to the Platform SDK for Windows 2000 or to the MSDN Library online.

© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Ammar Abuthuraya, Microsoft Corporation

Additional query words: kbGrpMDAC kbDSupport kbMDAC250bug

Keywords : kbGrpVCDB kbGrpMDAC kbDSupport kbMDAC250bug
Version : WINDOWS:2.5,6.0
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: January 3, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.