Microsoft KB Archive/245485

= PRB: Load From Stream Fails When Specifying MSPersist Provider =

Article ID: 245485

Article Last Modified on 2/24/2004

-

APPLIES TO


 * Microsoft Data Access Components 2.5
 * Microsoft Data Access Components 2.6
 * Microsoft Data Access Components 2.7
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q245485



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.



Steps to Reproduce Behavior
 Start a new Visual Basic project. Form1 is created by default. Add a Command button (Command1) to Form1. Add a Reference to Microsoft ActiveX Data Objects 2.x Library.  Paste the following code in the general declaration section of Form1.

Note You must change User ID  and 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 </li> Run the code to notice the behavior.</li></ol>

<div class="references_section">