search
Twitter Rss Feeds
MicrosoftArticlesForumsGroups
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml/Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

Web ProgrammingArticlesForumsGroups
JavaScript
ASP
ASP.NET
Web Services

Non-MicrosoftArticlesForumsGroups
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

DatabasesArticlesForumsGroups
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsGroups
Microsoft Excel
Microsoft Word
Microsoft Powerpoint
Publisher
Money

Operating SystemsArticlesForumsGroups
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsGroups
Share Point
BizTalk
Site Server
Exhange Server
IIS
Transaction Server

Graphic DesignArticlesForumsGroups
Macromedia Flash
Adobe PhotoShop
Microsoft Expression

OtherArticlesForumsGroups
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Reviews
Search Engines
Resumes

 
Insert Records - XML/ADO Marshalling Over The Net

By Robbe D. Morris

Printer Friendly Version


Robbe & Melisa Morris


Like many of our articles, this one was spawned from a forum question.  The basic question was this: "If I insert a record into an Access database on server A how can I marshall the ADO recordset and insert a duplicate record in another database on server B?".  Of course, most of us are aware of how to use the XMLHttp object and ADO to stream recordsets across the internet.  If you don't, that's ok.  Just read a past article entitled Web Services - Server To Server With XMLHttp and you'll learn all you need to know.  From this point forward, I'll assume you are familiar with the process and won't discuss it here.
In the code example below, I've combined both functions into one ASP file for ease of reading.  In a real world example, the sub InsertDB1() would reside on the web server supporting the database on server A.  The sub InsertDB2() would reside on the web server supporting the database on server B.  Of course, both would have your own functions for using XMLHttp to send and retrieve the data streams.
 
 
One of the major challenges I found was ADO's unwillingness to loadup an XML document with a connection open to a database.  To get around this in InsertDB2(), I opted to load the XML stream into a second disconnected ADO recordset.  Then, iterate through the recordset to build the standard .Fields parameters for the connected ADO recordset object all the while making sure I didn't create a parameter for the column in the table that holds the autonumber.  Upon completion, the .Update method is called and the new record is created in the second database.  Here's the code:


I'm guessing you'll want to make adjustments to the code above for reusability.  I wouldn't recommend using this type of methodology to replace large scale data replication available in enterprise level relational databases.  However, if the need ever arises where you would want to manipulate data in remote databases, you now know how to use the ADO recordset object and XML to complete your task.

Robbe has been a Microsoft MVP in C# since 2004.  He is also the co-founder of EggHeadCafe which provides .NET articles, book reviews, software reviews, and software download and purchase advice.


Pete's Blog   |    Pete's Resume   |    Robbe's Blog   |    Robbe's Resume   |    Archive #2   |    Archive #3   |    Dotnetslackers   |    XmlPitStop   |    Advertise   |   Contact Us   |   Privacy   |   Copyright (c) 2000 - 2009 eggheadcafe.com  All rights reserved.