FIX: CreateRecordset Method of Datafactory Fails w/ Text Field
ID: Q192138
|
The information in this article applies to:
-
Remote Data Service for ADO versions 1.5, 2.0
-
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0
SYMPTOMS
With a RDSServer.DataFactory component, build a disconnected recordset containing a text field greater then 32767 bytes, using the CreateRecordset method. This scenario creates the following error:
Invalid Procedure Call or Argument.
CAUSE
At present the column settings should adhere to the following constraints,
which clearly show that the third parameter is an integer whose value
should be less then or equal to 32767:
Column Name : String (BSTR)
Column Type : Integer (VT_I2)
Column Size : Integer (VT_I2)
Column IsNullable : Bool (VT_BOOL)
RESOLUTION
The workaround is to set the field size greater then 255 bytes. This
automatically converts the field type to adLongVarChar and can hold more than a 2 MB string.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
This problem has been fixed in MDAC 2.1 SP2.
MORE INFORMATION
Steps to Reproduce Behavior
- Open a new Standard .exe project in Visual Basic. Form1 is created by default.
- Add a Command button to the form.
- From the Project menu, click References, and then select both of the
following references:
- Microsoft ActiveX Data Objects 1.5 or 2.0 Recordset Library
- Microsoft Remote Data services server 1.5 or 2.0 Library
NOTE: These libraries can be mistaken for the following libraries by accident:
- Microsoft ActiveX Data Objects 1.5 or 2.0 Library
- Microsoft Remote Data Services 1.5 or 2.0 Library
- Paste the following code in the Code window:
Private Sub Command1_Click()
Dim blankrec As New DataFactory
Dim rst As ADOR.Recordset
Dim Record(0) As Variant
Dim Col1(3) As Variant
Dim str As String, i As Long
' Use the RDSServer.DataFactory to create an empty
' recordset. It takes an array of variants where
' every element is another array of
' variants, one for every column required in the
' recordset.
' The elements of the inner array are the column's
' name, type, size and nullability.
Col1(0) = "Text1"
Col1(1) = CInt(adLongVarChar)
' For our first pass this line remains uncommented to produce
' the error.
Col1(2) = 32768 'In order to pass a 32KB string.
' The following, when uncommented, creates the recordset without
' the error.
'Col1(2) = 256
Col1(3) = True
Record(0) = Col1
Set rst = blankrec.CreateRecordSet(Record) ' You get an error here
' when col2(2) > 32767.
For i = 1 To 1024 ' Build a 2MB string.
str = str & String(2000, "x")
Next i
rst.AddNew
rst(0) = str
rst.Update
Debug.Print rst(0).ActualSize 'To prove that the field holds
'the 2MB string.
End Sub
- Press the F5 key to run the example. Click Command1.
- The following error appears:
Invalid Procedure Call.
- Uncomment this line of Code:
Col1(2) = 256 and comment Col1(2) = 32768
- Press the F5 key to run the example. Click Command1. In the Debug window the value is 2048000 bytes. The value proves that the recordset contains a text field with 2MB of data even though the size of the field is set to 256 bytes.
REFERENCES
RDS Help; search on: "CreateRecordset"
Additional query words:
Keywords : kbRDS150 kbRDS150bug kbRDS200 kbRDS200bug kbVBp500 kbVBp600 kbGrpVBDB kbGrpMDAC kbDSupport kbADO210sp2 kbRDS210SP2bug kbMDAC210SP2fix
Version : WINDOWS:1.5,2.0,5.0,6.0
Platform : WINDOWS
Issue type : kbbug