Microsoft KB Archive/265792

= DB2OLEDB Leaks Memory When Stored Procedure Returns Large VarChar =

Article ID: 265792

Article Last Modified on 2/12/2004

-

APPLIES TO


 * Microsoft SNA Server 4.0 Service Pack 3

-



This article was previously published under Q265792



SYMPTOMS
If an application uses the Microsoft OLE/DB for DB2 Provider to receive a large adLongVarChar parameter (for example, 25,000 bytes) from a stored procedure call, the Db2oledb.dll and Db2serv.exe processes may leak memory.

The memory leak in Db2serv.exe occurs whenever the stored procedure call completes, and is visible in Performance Monitor by viewing the Private Bytes of the application process and the Db2serv.exe process. When the application ends, the Db2serv.exe memory never decreases. Over time, Db2serv.exe will grow indefinitely in size. If the stored procedure call is implemented in a COM object and invoked repeatedly from a Visual Basic program, the following error message may occur:

80004005 (unspecified error)



CAUSE
This is caused by a problem in the DB2 Provider's support for stored procedures.



RESOLUTION
To resolve this problem, obtain the latest service pack for SNA Server 4.0. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

215838 How to Obtain the Latest SNA Server Version 4.0 Service Pack



STATUS
Microsoft has confirmed that this is a problem in Microsoft SNA Server 4.0 SP3.

This problem was first corrected in SNA Server 4.0 Service Pack 4.



MORE INFORMATION
The following Visual Basic sample is used to reproduce the problem. The data link properties in the UDL file point to an IBM DB2 system configured with a stored procedure name of SPSAMPLE, which returns an adLongVarChar parameter of 25,000 bytes.

Attribute VB_Name = &quot;Form1&quot; Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click

Dim recset1 As New ADODB.Recordset Dim connection1 As New ADODB.Connection On Error GoTo ErrorHandler

'Can see memory usage increase with each repetition of this test For x = 0 To 500 connection1.ConnectionString = &quot;File Name=C:\DB2.UDL&quot; 'Connection connection1.CursorLocation = 2 connection1.Open Set cmd = New ADODB.Command cmd.Prepared = True cmd.CommandText = &quot;CALL SPSAMPLE (?,?,?)&quot; cmd.CommandType = adCmdText ' Get parameter value and append parameter. Set param = cmd.CreateParameter(&quot;foo1&quot;, adLongVarChar, adParamOutput) param.Size = 25002 cmd.Parameters.Append param ' Get parameter value and append parameter. Set param = cmd.CreateParameter(&quot;foo2&quot;, adInteger, adParamOutput) param.Value = 0 param.Size = 4 cmd.Parameters.Append param ' Get parameter value and append parameter. Set param = cmd.CreateParameter(&quot;foo3&quot;, adInteger, adParamOutput) param.Value = 0 param.Size = 4 cmd.Parameters.Append param ' Create recordset by executing the command. Set cmd.ActiveConnection = connection1 cmd.Execute 'The parameter should consist of &quot;VARIABLE CHARACTER STRING OF 25000 'BYTES IN LENGTH&quot; repeated 499 times. The very last piece of text in    'the varchar is &quot;THE VERY VERY VERY LAST  CHARACTER STRING&quot;. 'Debug.Print Len(cmd.Parameters(0).Value) 'Debug.Print cmd.Parameters(0).Value 'Clean Up    Set param = Nothing Set cmd = Nothing Set connection1 = Nothing Next x EndMsg = MsgBox(&quot;Test Finished&quot;, vbOKOnly, &quot;SPSAMPLE&quot;) Exit Sub ErrorHandler: ' Output error message MsgBox Error

End Sub

Keywords: kbbug kbfix kbsna400presp4fix kbqfe kbsna400sp4fix KB265792

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.