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



The information in this article applies to:

  • Microsoft Data Access Components 2.6, when used with:
    • the operating system: Microsoft Windows NT 4.0
  • Microsoft Data Access Components 2.6 SP1, when used with:
    • the operating system: Microsoft Windows NT 4.0
  • Microsoft Data Access Components 2.7, when used with:
    • the operating system: Microsoft Windows NT 4.0
  • Microsoft ODBC Driver for SQL Server 2000.80.194

This article was previously published under Q305676

SYMPTOMS

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.

CAUSE

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

RESOLUTION

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)
      						

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"
        
        m_oConn.Close
        Set m_oConn = Nothing
        DoEvents
    Wend
    
    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.

Modification Type:MajorLast Reviewed:5/8/2003
Keywords:kbprb KB305676