Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Load From Stream Fails When Specifying MSPersist Provider


View products that this article applies to.

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.

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


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.x Library.
  4. Paste the following code in the general declaration section of Form1.

    Note You must change User ID <User ID> and password <Strong Password> to the correct values. Make sure that User ID has the appropriate permissions to perform this operation on the database.
    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:\MyFile.xml") <> "" Then
            Kill "C:\MyFile.xml"
        End If
        
        rs.Open "SELECT * FROM authors", "DSN=pubs;uid=<User ID>;pwd=<Strong Password>;", _
                 adOpenStatic, adLockReadOnly, adCmdText
        rs.Save "C:\MyFile.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:\MyFile.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
    					
  5. Run the code to notice the behavior.

↑ Back to the top


References

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

↑ Back to the top


Article Info
Article ID : 245485
Revision : 5
Created on : 1/1/0001
Published on : 1/1/0001
Exists online : False
Views : 330