Microsoft KB Archive/288403

= PRB: Visual Basic String (BSTR) in Variant Field in ADO Recordset Cannot Be Persisted to ADTG =

Article ID: 288403

Article Last Modified on 5/8/2003

-

APPLIES TO


 * Microsoft Data Access Components 2.1
 * Microsoft Data Access Components 2.1 Service Pack 2
 * Microsoft Data Access Components 2.1 Service Pack 1
 * Microsoft Data Access Components 2.1 Service Pack 2
 * Microsoft Data Access Components 2.5
 * Microsoft Data Access Components 2.5 Service Pack 1
 * Microsoft Data Access Components 2.6
 * Microsoft Data Access Components 2.7

-



This article was previously published under Q288403



SYMPTOMS
If you create an ActiveX Data Objects (ADO) or ADOR recordset with a field of type adVariant, and populate that field with a Microsoft Visual Basic string value, then call the Recordset's Save method, specifying ADTG as the persistence format, the Save method appears to work with MDAC 2.1, but fails under MDAC version 2.5 or later with the following error message:

Run time error -2147217891 (80040e1d) Requested conversion is not supported



CAUSE
The ADTG persistence format available for ADO Recordsets does not support the following Variant field types: VT_RECORD, VT_ILLEGAL, VT_VARIANT, VT_UNKNOWN, VT_BSTR, and VT_DISPATCH. These variant subtypes are explicitly disallowed by the persistence provider for ADTG. The XML persistence format supports a slightly different set of types.



RESOLUTION
Because Visual Basic strings cannot be persisted to ADTG format in a field of ADO datatype adVariant, a string datatype such as adChar or adVarchar must be used for Visual Basic string fields.



STATUS
This behavior is by design and is now more clearly documented in the MDAC 2.5 documentation than in previous MDAC documentation versions.



MORE INFORMATION
Under MDAC 2.1, the attempt to persist a Visual Basic string in ADTG format in an adVariant field did not generate an error message. However the data that MDAC 2.1 saved in this case was not, in fact, valid. Therefore, the error message that is raised by MDAC 2.5 or later indicates improved error-handling in the persistence provider, not a change in behavior.

Steps to Reproduce Behavior
  Paste the following code into an event procedure in a Visual Basic project, with a reference to the ADOR library. Note that field &quot;C&quot; is of type adVariant and is being filled with Visual Basic String values. Dim intI As Integer Dim RS As ADOR.Recordset Dim strTempFile As String Dim varV As Variant Set RS = New ADOR.Recordset With RS   .Fields.Append &quot;A&quot;, adInteger .Fields.Append &quot;B&quot;, adBSTR .Fields.Append &quot;C&quot;, adVariant,, adFldIsNullable .Fields.Append &quot;D&quot;, adSingle .Fields.Append &quot;E&quot;, adSmallInt .Fields.Append &quot;F&quot;, adTinyInt .Fields.Append &quot;G&quot;, adBigInt .Fields.Append &quot;H&quot;, adBoolean .Fields.Append &quot;I&quot;, adDBTimeStamp .Open .Fields(&quot;A&quot;).Properties(&quot;Optimize&quot;) = True End With For intI = 1 To 100 RS.AddNew varV = &quot;abcde&quot; With RS       .Fields(&quot;A&quot;) = intI .Fields(&quot;B&quot;) = &quot;abcde&quot; .Fields(&quot;C&quot;) = varV .Fields(&quot;D&quot;) = 123.456 .Fields(&quot;E&quot;) = 10000 .Fields(&quot;F&quot;) = 100 .Fields(&quot;G&quot;) = 1000000 .Fields(&quot;H&quot;) = True .Fields(&quot;I&quot;) = Now End With RS.Update Next intI

strTempFile = &quot;c:\ADOPersistence.TMP&quot; On Error Resume Next Kill strTempFile On Error GoTo 0 RS.Save strTempFile, adPersistADTG RS.Close  Test the code with MDAC 2.1, and note that it appears to succeed. Test the code with MDAC 2.5 or later, and note that it fails with the conversion error message noted in the &quot;Symptoms&quot; section.

Additional query words: stops responding

Keywords: kbprb KB288403

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.