0

I'm trying to retrieve an XML column from a table in a DB2 database. Using the code below, I can retrieve any column that does not have xml as the data-type:

query = "some query"  
strConn = "my connection string"  
set dbConn = CreateObject("ADODB.Connection")  
set rs = CreateObject("ADODB.RecordSet")  
dbConn.Open strConn  
rs.Open query, dbConn  

rs.MoveFirst  
While Not rs.EOF  
 data = rs.Fields(0)  
 rs.MoveNext  
Wend  
dbConn.Close  

When the data is an xml data-type, the line "data = rs.Fields(0)" throws an "unspecified error". I thought since the recordset returns an XML object, I need to assign it to a DOM object like this:

Set xDOM = CreateObject("Microsoft.XMLDOM")  
rs.Save xDOM, adPersistXML  

but this still doesn't work, QTP throws an "unspecified error" when executing the save line.

I googled for an answer but couldn't find anything that would help. Is there anyone out there who has successfully done this?

Thanks for reading my question.

Charles
  • 50,943
  • 13
  • 104
  • 142

1 Answers1

0

According to DB2 - .NET datatypes, DB2Xml maps to Byte()/Blob. So perhaps you can deal with your XML field as Mr. Gates deals with pictures, e.g.:

Set cn = New ADODB.Connection   ---> CreateObject("ADODB.Connection")
cn.Open "DB2 Connection String"

Set rs = New ADODB.Recordset    ---> CreateObject("ADODB.Recordset")
rs.Open "Your SQL", cn, adOpenKeyset, adLockOptimistic ---> Const defines needed

Set mstream = New ADODB.Stream ---> CreateObject("ADODB.Stream")
mstream.Type = adTypeBinary ---> Const define needed
mstream.Open
mstream.Write rs.Fields("Your XML field").Value
mstream.SaveToFile "fullfilespec.xml", adSaveCreateOverWrite ---> Const define needed

rs.Close
cn.Close

(obviously untested aircode)

P.S. Your rs.Save xDOM, adPersistXML is completely wrong; .Save saves the whole recordset to a file specified as first parameter.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96