Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ADODB Serialization

0.00/5 (No votes)
26 Sep 2006 1  
How to serialize and deserialize an ADODB Recordset.

Introduction

I came across the other day with a need to create a .Net interface to allow a COM client to use .NET Remoting. The COM client use ADO Recordset heavily.

When using remoting it is not possible to send a ADO recordset as a return value. The same will apply when using a web service.

I tried googling on the subject but the only article I found was to save the Recordset as a DataSet then save it back to a ADODB Recordset. There had to be a easier solution. After trial and errors. I found the perfect solution (it could be adapted easily for web service, simply uuEncode and decode the byte array)

Here it is, with just a few lines of code....

The Code

<pre>
using System;

using ADODB;

 

namespace InteropSample

{

public static class RsUtil

{

 

   public static byte[] SerializeRs(Recordset rs)

  {

     ADODB.Stream s = new ADODB.Stream();

     rs.Save(s, ADODB.PersistFormatEnum.adPersistADTG);

     return (byte[])s.Read(s.Size);

  }

  public static Recordset DeserializeRs(byte[] data)

  {

     ADODB.Stream s = new ADODB.Stream();

     s.Open(Missing.Value, ConnectModeEnum.adModeUnknown, 

     ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "");

     s.Type = ADODB.StreamTypeEnum.adTypeBinary;

     s.Write(data);

     s.Position = 0;

     Recordset rs = new Recordset();

     rs.Open(s, Missing.Value, CursorTypeEnum.adOpenUnspecified, 

               LockTypeEnum.adLockUnspecified, -1);

     return rs;

  }

 }

}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here