Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Memory Leak When MDAC Is Running on Windows NT 4.0

View products that this article applies to.

This article was previously published under Q305676

↑ Back to the top


When you use the ODBC Driver for SQL Server with MDAC 2.6 or later under Windows NT 4.0, you may notice a memory leak.

↑ Back to the top


This problem occurs because Dbnetlib.dll does not stay in memory.

↑ Back to the top


There are two ways to work around this problem:
  • Use the OLE DB provider for SQL Server.
  • Make the following code changes:
    1. Add the following application programming interface (API) declaration to a module in your project:
      Public Declare Function LoadLibrary Lib "kernel32" & _
         Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    2. Add the following code, which forces Dbnetlib.dll to stay in memory:
      Dim handle As Long
      Dim DLLName As String
      ' DBNETLIB.DLL should be located in the NT System directory.
      DLLName = "C:\WINNT\System32\DBNETLIB.DLL"
      handle = LoadLibrary(DLLName)

↑ Back to the top

More information

Steps to Reproduce Behavior

  1. Create a system DSN named SQLTest that points to your SQL Server.
  2. Create a new Standard EXE project in Visual Basic. Form1 is created by default.
  3. Add the following code to Form1:
    Private Sub Form_Load()
    Dim m_oConn As ADODB.Connection
    Dim counter As Long
    'Dim handle As Long
    'Dim DLLName As String
    ' DBNETLIB.DLL should be located in the NT System directory.
    'DLLName = "C:\WINNT\System32\DBNETLIB.DLL"
    'handle = LoadLibrary(DLLName)
    While (1)
        counter = counter + 1
        Set m_oConn = New ADODB.Connection
        m_oConn.Open "DSN=SQLTest"
        Set m_oConn = Nothing
    End Sub
  4. In Perfmon, add a counter that contains the following settings:
    Performance object: Process
    Select Counters from list: Private bytes
    Select Instances from list: VB6
  5. Run the application, and observe the Perfmon counter.

↑ Back to the top

Keywords: KB305676, kbprb

↑ Back to the top

Article Info
Article ID : 305676
Revision : 3
Created on : 5/8/2003
Published on : 5/8/2003
Exists online : False
Views : 395