Microsoft KB Archive/296772

= How To Send a Binary Stream by Using XMLHTTP =

Article ID: 296772

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0
 * Microsoft XML Parser 3.0 Service Pack 1
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q296772



SUMMARY
In some cases you may want to send a binary stream to a server. One way to do so is to use the IXMLHTTPRequest object. This article demonstrates how to retrieve an ADO recordset from a server, modify it, and send it back as a stream of binary data.



MORE INFORMATION
This example uses the ADODB.Stream object to hold the binary data that is to be sent back to the server. If a newer version of MSXML has been installed in Side-by-Side mode, then to run the sample code with that specific version, you must explicitly use the GUIDs or ProgIDs for that version. For example, MSXML version 4 only installs in side-by-side mode. Please refer to the following article in the Microsoft Knowledge Base to see what code changes required to run the sample code with the MSXML 4.0 parser: Q305019 INFO: MSXML 4.0 Specific GUIDs and ProgIds.

For example, in the code below, you would create objects with MSXML 4.0 with the following statements:
 * var xmlhttp = new ActiveXObject(&quot;Msxml2.XMLHTTP.4.0&quot;);
 * xmldoc = new ActiveXObject(&quot;Msxml2.DOMDocument.4.0&quot;);
 * var xmlhttp = new ActiveXObject(&quot;Msxml2.XMLHTTP.4.0&quot;);

To use XMLHTTP to send a binary stream to a server, follow these steps:   Paste the following code into a file in your default Web folder and name the file Receiver.asp. <% dim Connection dim rs Connection = &quot;Provider=SQLOLEDB.1;Data Source=servername;User Id=username;Password=password;Initial Catalog=Northwind;&quot; sql = &quot;Select * from Customers&quot;

set rs = server.CreateObject(&quot;ADODB.Recordset&quot;)

if Request.QueryString(&quot;getRecordset&quot;) = &quot;YES&quot; then rs.ActiveConnection = Connection rs.CursorLocation = 3 'Client Side rs.CursorType = 3 'Static Recordset rs.LockType = 4 'Batch Optimistic rs.Open sql rs.Save response, 1 'persist adPersistXML Response.End else rs.open Request '.BinaryRead(Request.TotalBytes) rs.activeconnection = Connection 'Reconnect rs.updatebatch 'Update adAffectAll rs.close Response.Write &quot;Recordset Saved&quot; 'Send back response Response.End end if

%>   Paste the following code into a file in your default Web folder and name the file Sender.asp 

     Modify the Receiver.asp page so that the connection variable contains a Microsoft SQL Server name and a valid SQL userid and password. Start Microsoft Internet Explorer and browse to http://localhost/sender.asp.</li> Click Get Recordset. A message box appears and tells you that the recordset was loaded successfully.</li> Click Update. A message box appears and shows you the value before the update. A second message box appears and shows you the value after the update.</li> Click Send Recordset. A message box appears and tells you that the recordset was updated.</li></ol>

Known Limitations and Recommendations
<ul> Although this allows you to use the persist mechanism to pass the data back and forth to the client, it is recommended that you use UpdateGrams or OpenXML with SQL Server 2000 to pass and send recordset data in XML format.</li> There are limitations in shaped recordsets. Edited shaped recordsets cannot be persisted in XML format. Also, parameterized shaped commands cannot be persisted at all. For additional information on persisting and limitations, see the following Microsoft Developer Network (MSDN) Web site:

XML Persistence Format

http://msdn.microsoft.com/library/psdk/dasdk/xmli3vsk.htm

</li></ul>

<div class="references_section">