BUG: No Error Given in ADO When Saving or Marshalling Recordset with Non-Null Columns (304168)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7
  • Microsoft Data Access Components 2.8

This article was previously published under Q304168

SYMPTOMS

If you persist a recordset with empty values at non-nullable columns to an Extensible Markup Language (XML) file by using the Save Method of an ADO Recordset, incorrect data is saved, and no error occurs.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a table in Microsoft SQL Server by using the following script:

    Note You can cut and paste the statements directly into the SQL Query Analyzer tool, the ISQL utility, or the OSQL utility.
     CREATE TABLE [dbo].[rctest] (
     [myid] [int] IDENTITY (1, 1) NOT NULL ,
     [mytext] [varchar] (255) NULL ,
     [mynum] [int] NOT NULL ,
     [mydate] [datetime] NOT NULL ,
     [mytext2] [varchar] (255) NOT NULL
     )
     GO
    					
  2. In Microsoft Visual Basic, create a new Standard EXE project. Form1 is created by default.
  3. On the Project menu, click Components. From the list of available components, select Microsoft ADO Data Control 6.0(OLEDB) and Microsoft DataGrid Control 6.0(OLEDB).
  4. On the Project menu, click References. From the list of available references, select Microsoft ActiveX Data Objects 2.8 Library.
  5. Place a DataGrid control and a CommandButton control on Form1.
  6. Set the AllowAddNew property of the DataGrid to True.
  7. Paste the following code in the Declarations section of Form1:

    Note You must change User ID=<UID> and password=<strong password> to the correct values before you run this code. Make sure that <UID> has the appropriate permissions to perform this operation on the database.
    Option Explicit
    
    Dim cn As New ADODB.Connection
    Dim rs1 As New ADODB.Recordset
    
    Private Sub Form_Load()
       cn.Open "Provider=SQLOLEDB.1;Data Source=<servername>;user id=<UID>;" & _
               "Password=<strong password>;Initial catalog=<databasename>"
       rs1.CursorLocation = adUseClient
       rs1.Open "Select * from rctest where 1 = 2", cn, _
            adOpenStatic, adLockBatchOptimistic
       Set rs1.ActiveConnection = Nothing
       Set DataGrid1.DataSource = rs1
    End Sub
    
    Private Sub Command1_Click()
       Dim stm As New ADODB.Stream
       Dim fld As ADODB.Field
       rs1.Save stm, adPersistXML
       stm.SaveToFile "c:\temp\xmlnull.xml", adSaveCreateOverWrite
       rs1.Close
       rs1.Open stm
       Set DataGrid1.DataSource = rs1
    
       While Not rs1.EOF
          For Each fld In rs1.Fields
             Debug.Print fld.Value
          Next
          rs1.MoveNext
       Wend
    End Sub
    					
  8. Run the project.
  9. Add data to the Mytext column by using the grid. Add three more rows of data. Only enter data in the Mytext column for all rows entered.
  10. Click Command1. Note that the Xmlnull.xml file is created in the C:\Temp folder. You can see that the schema is correct. That is, the required columns show the rs:maybenull='false' attribute. However, no data is saved for those required columns, which makes the data incorrect according to the schema. An error should occur at the Save method indicating that required data was not provided.

    When the grid is populated, zeros are displayed for the integer fields (Mynum and Myid), #ERROR is displayed at the date field (Mydate), and an empty string is displayed at the Mytext columns.

Modification Type:MajorLast Reviewed:11/5/2003
Keywords:kbbug kbpending KB304168