Exchange Data Between VB6 and VB.NET Apps
by Andy Leonard
September 2003 Issue
Technology Toolbox: VB.NET, SQL Server 2000, XML, VB6
You can use XML to persist data in both VB6 and VB.NET applications. You can persist ADO recordsets as XML in VB6, and you can persist ADO.NET data sets as XML in VB.NET. The question is: Can you use these mechanisms to achieve an exchange of data between VB6 and VB.NET applications? The answer is: "Yes, however … ."
Like me, you would probably surmise that ADO.NET allows you to read an XML-persisted ADO recordset from within your VB.NET application. Like me, you would be mistaken. Is it possible to read an XML-persisted recordset? Sure. Is it simply a matter of passing the adUseADORecordsetXMLSchema argument as a parameter when filling a data set? Far from it. (adUseADORecordsetXMLSchema doesn't exist, but I think it should.) Attempting to open an ADO recordset persisted to XML with ADO.NET generates an error (see Figure 1).
You've probably divided your .NET migration project into two phases, believing you could rewrite the Data layer in .NET to read all that XML that the business layer generates in VB6. You're not stuckyour strategy is just out of order. You can rewrite the business layer in .NET to persist data sets in XML in the ADO recordset format, with the help of a snappy DLL from Microsoft support.
The ConvertDStoRS.dll is available, at the time of this writing, on the Microsoft Product Support Services Web site, article 316337 (see Additional Resources). The source code for the DLL is provided with the download. Take a look at
two applicationsone for VB6 and one for VB.NETto demonstrate what you can and cannot achieve with this DLL. You'll need access to an instance of SQL Server with the Pubs database installed for these to function properly.
Create a directory called "XML" on your C:\ drive (or elsewherejust remember to edit the code appropriately), and place the "ConvertDStoRS.xsl" file in this directory. (Note: ConvertDStoRS.xsl is listed in the Microsoft Product Support Services article as "test.xsl"; see Additional Resources.) Decompress and open VB6_XMLOps in the VB6 IDE. Modify the SQL Server connection strings to match your instance of SQL Server, and press F5 to run the application in Debug mode (see Figure 2).
When you click on the "Write ADO RS" CommandButton, the application executes a query against the Pubs database, returning the contents of the Authors table in an ADO recordset. Next, the contents of this recordset are persisted as an XML file to the indicated path. Click on "Write ADO RS" to generate the XML file.
Back to top