BUG: Access Violation with ADO Recordset and Connection Objects in .NET Framework (312111)



The information in this article applies to:

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

This article was previously published under Q312111

SYMPTOMS

You may encounter an access violation and slower connectivity if you do not explicitly close the ActiveX Data Objects (ADO) Recordset and Connection objects.

CAUSE

If you do not close your objects explicitly, the .NET Framework employs garbage collection while the references still exist. Even if you never use the reference again, an access violation can occur.

RESOLUTION

To resolve this problem, always close the ADO Recordset and Connection objects. For example:
     Dim cn as ADODB.Connection
     Dim rs as ADODB.Recordset
     'Perform necessary tasks.
     rs.Close
     cn.Close
				

STATUS

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

MORE INFORMATION

When you use an ADO Recordset object (ADODB.Recordset) or an ADO Connection object (ADODB.Connection) with .NET Framework applications, always call the Close method when you finish. This ensures that the underlying connection to the data source is released in a timely manner. This also prevents possible access violations, which can occur because garbage collection reclaims unmanaged ADO objects when existing references still exist. This problem most often occurs with garbage collection when the applications are under stress or high usage.

Modification Type:MinorLast Reviewed:5/28/2003
Keywords:kbbug kbpending kbreadme KB312111