Microsoft KB Archive/293876

= FIX: Memory Leak When You Use Now Function in SQL with Jet 4.0 Provider or Driver =

Article ID: 293876

Article Last Modified on 1/6/2004

-

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

-



This article was previously published under Q293876



SYMPTOMS
If an application connects to a database using the Microsoft Access ODBC Driver or the Microsoft OLE DB Provider for Jet version 4.0, and if the application uses the Now function of the Visual Basic for Applications in the WHERE clause of a SQL query, a memory leak occurs. If you use the function repeatedly, eventually enough memory leaks so that the application fails (crashes).



RESOLUTION
Install the latest Microsoft Jet 4.0 service pack. For additional information about how to install the latest Jet service pack, click the following article number to view the article in the Microsoft Knowledge Base:

239114 How To: Obtain the Latest Service Pack for the Microsoft Jet 4.0 Database Engine



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



Steps to Reproduce Behavior
 Create a new Visual Basic Standard EXE project. Form1 is created by default. Set a reference to Microsoft ActiveX Data Objects (ADO). Place a timer control on Form1, and set its Interval property to a value such as 1000.  Paste the following code: Dim m_connADO As ADODB.Connection

Private Sub Form_Load Set m_connADO = New ADODB.Connection m_connADO.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _ &quot;Data Source=C:\Program Files\Microsoft Visual Studio\Vb98\nwind.mdb;&quot; End Sub

Private Sub Form_Unload(Cancel As Integer) Timer1.Enabled = False m_connADO.Close Set m_connADO = Nothing End Sub

Private Sub Timer1_Timer Dim rsTemp As ADODB.Recordset Dim strQry As String Debug.Print &quot;Timer event: &quot; & Now strQry = &quot;SELECT * FROM Orders WHERE OrderDate <= Now&quot; Set rsTemp = m_connADO.Execute(strQry) rsTemp.Close Set rsTemp = Nothing End Sub  Run the project, and use the Performance Monitor tool or Task Manager to monitor the memory usage.</ol>

<div class="references_section">