Click here to Skip to main content
13,291,084 members (69,538 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 26 Sep 2006

ADODB Serialization

, 26 Sep 2006
Rate this:
Please Sign up or sign in to vote.
How to serialize and deserialize an ADODB Recordset.


I came across a need to create a .NET interface to allow a COM client to use .NET Remoting. The COM client heavily uses ADO Recordsets.

When using Remoting, it is not possible to send an 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 an ADODB Recordset. There had to be an easier solution. After trial and errors, I found the perfect solution (it could be adapted easily for a Web Service: simply uuEncode and decode the byte array).

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

The Code

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.Position = 0;
            Recordset rs = new Recordset();
            rs.Open(s, Missing.Value, CursorTypeEnum.adOpenUnspecified, 
            LockTypeEnum.adLockUnspecified, -1);
            return rs;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Canada Canada
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 26 Sep 2006
Article Copyright 2006 by StephHamel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid