FIX: System.StackOverflowException Error When You Access the UnderlyingValue Property (316319)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7
  • Microsoft .NET Framework 1.0

This article was previously published under Q316319

SYMPTOMS

When you try to access the Underlying Value property of a field by using ActiveX Data Objects (ADO) with the Component Object Model (COM) interoperability layer, you may encounter the following exception:
An unhandled exception of type 'System.StackOverflowException' occurred in adodb.dll

RESOLUTION

To work around this problem, declare the variable as type Object instead of Recordset to late bind the Recordset object, as in the following example:
Dim rs As Object = New Recordset()
				

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Windows .NET Framework 1.1 .

MORE INFORMATION

Steps to Reproduce the Problem

  1. Start Microsoft Visual Studio .NET.
  2. Create a new Windows Application project in Visual Basic .NET.
  3. Place a Button control on Form1, and change its Name property to btnTest.
  4. In Solution Explorer, right-click References, and then click Add Reference.
  5. On the .NET tab in the Add Reference dialog box, click ADODB.dll, click Select to add this reference to the Selected Components section, and then click OK.
  6. Use the Imports statement on the ADODB namespace so that you are not required to qualify declarations in those namespaces later in your code. Add the following code to the "General Declarations" section of Form1:
             Imports ADODB
    					
  7. Copy and paste the following code in the code window after the "Windows Form Designer generated code" region:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cn As New Connection()
    
        'Declare the variable as RecordSet
        Dim rs As New Recordset()
        'Comment the previous line and uncomment the next line of Code to declare the variable as Object
        'Dim rs As Object = New Recordset()
    
        Dim fld As Field
        Dim Conn As String
        Dim DelQuery As String
        Dim CreateQuery As String
        Dim InsQuery As String
        Dim SelQuery As String
    
        Conn = "Provider=SQLOLEDB.1;User ID=username;Password=password;" & _
                "Initial Catalog=pubs;Data Source=ServerName"
    
        DelQuery = "If exists (Select * from SysObjects where id = object_id(N'[dbo].[TestTable]')" & _
            "and OBJECTPROPERTY(id, N'IsUserTable') = 1)" & _
            "Drop table [dbo].[TestTable]"
        CreateQuery = "Create table TestTable (fld1 integer primary key, fld2 varchar(20))"
        InsQuery = "Insert into TestTable values (1, '1')"
        SelQuery = "Select * from TestTable"
    
        cn.CursorLocation = CursorLocationEnum.adUseClient
        cn.Open(Conn) 'Open Connection
        cn.Execute(DelQuery) 'Delete table if it already exists
        cn.Execute(CreateQuery) 'Create a new table 
        cn.Execute(InsQuery) 'Insert data
    
        rs.Open(SelQuery, cn, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockOptimistic)
        rs.Fields(1).Value = "Test"
        Debug.WriteLine(rs.Fields(1).Value)
        Debug.WriteLine(rs.Fields(1).UnderlyingValue) 'This line will cause the above mentioned exception
    End Sub
    					
  8. Modify the connection string (Conn) as appropriate for your environment.
  9. Save your project.
  10. On the Debug menu, click Start to run your project.

    Note that the code fails with the above-mentioned exception when you try to access the UnderlyingValue property of the field.
  11. Create the Recordset variable as an Object.
  12. On the Debug menu, click Start to run your project

REFERENCES

For more details about the .NET Framework and the COM Interop layer, browse to the following MSDN Web site: For more information about UnderlyingValue property, refer to the following MSDN Web sites:

Modification Type:MajorLast Reviewed:9/26/2006
Keywords:kbfix kbbug kberrmsg kbnofix KB316319