Microsoft KB Archive/250315: Difference between revisions
m (Text replacement - "<" to "<") |
m (Text replacement - """ to """) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 84: | Line 84: | ||
<li><p>Paste the following code in the form module of Form1:<br /> | <li><p>Paste the following code in the form module of Form1:<br /> | ||
<br /> | <br /> | ||
'''Note''' You must change User ID=<User ID | '''Note''' You must change User ID=<User ID> to the correct value before you run this code. Make sure that User ID has the appropriate permissions to perform this operation on the database.</p> | ||
<pre class="codesample">Option Explicit | <pre class="codesample">Option Explicit | ||
Line 92: | Line 92: | ||
Dim crs As Object | Dim crs As Object | ||
Set cnn = CreateObject( | Set cnn = CreateObject("ADODB.Connection") | ||
cnn.Open | cnn.Open "Provider=SQLOLEDB;Data Source=servername;" & _ | ||
"Initial Catalog=pubs;User ID=<User ID>;" | |||
Set rs = New ADODB.Recordset | Set rs = New ADODB.Recordset | ||
rs.CursorLocation = adUseServer | rs.CursorLocation = adUseServer | ||
'rs.CursorLocation = adUseClient | 'rs.CursorLocation = adUseClient | ||
rs.Open | rs.Open "select * from authors where au_lname like 'S%'", _ | ||
cnn, adOpenStatic, adLockReadOnly | cnn, adOpenStatic, adLockReadOnly | ||
Dim i As Long | Dim i As Long | ||
For i = 0 To 120000 | For i = 0 To 120000 | ||
Set crs = rs.Clone | Set crs = rs.Clone | ||
crs.Filter = | crs.Filter = "Au_Lname = 'Smith'" | ||
crs.Close | crs.Close | ||
Set crs = Nothing | Set crs = Nothing |
Latest revision as of 13:51, 21 July 2020
Article ID: 250315
Article Last Modified on 5/17/2007
APPLIES TO
- Microsoft ActiveX Data Objects 2.5
This article was previously published under Q250315
SYMPTOMS
If you clone a server-side ADO Recordset object, you may encounter a memory leak. This behavior can occur in varying degrees in any of the following products:
- Microsoft OLE DB Provider for ODBC
- Microsoft OLE DB Provider for Jet, version 4.0
- Microsoft OLE DB Provider for SQL Server
RESOLUTION
If it is necessary to clone a Recordset, use a client-side cursor.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in ActiveX Data Objects (ADO), version 2.6. You can download the latest version of ADO from the following Microsoft Web site:
MORE INFORMATION
Steps to Reproduce Behavior
- Create a new Standard EXE project in Visual Basic. Form1 is created by default.
- From the Project Menu, click References, and select the Microsoft Active X Data Object 2.5 check box.
Paste the following code in the form module of Form1:
Note You must change User ID=<User ID> to the correct value before you run this code. Make sure that User ID has the appropriate permissions to perform this operation on the database.Option Explicit Private Sub Form_Load() Dim cnn As ADODB.Connection Dim rs As ADODB.Recordset Dim crs As Object Set cnn = CreateObject("ADODB.Connection") cnn.Open "Provider=SQLOLEDB;Data Source=servername;" & _ "Initial Catalog=pubs;User ID=<User ID>;" Set rs = New ADODB.Recordset rs.CursorLocation = adUseServer 'rs.CursorLocation = adUseClient rs.Open "select * from authors where au_lname like 'S%'", _ cnn, adOpenStatic, adLockReadOnly Dim i As Long For i = 0 To 120000 Set crs = rs.Clone crs.Filter = "Au_Lname = 'Smith'" crs.Close Set crs = Nothing Next i rs.Close cnn.Close Set rs = Nothing Set cnn = Nothing End Sub
- Modify the connection string to connect to your Microsoft SQL Server database.
- Start Performance Monitor, and monitor the private bytes for the Visual Basic 6.0 process.
- Run the code, and notice that the private bytes increase steadily. When the private bytes reach 100 percent, most likely the application locks up.
Uncomment the following line of code:
'rs.CursorLocation = adUseClient
and comment the following line:
rs.CursorLocation = adUseServer
- Run the application, and monitor the private bytes. Notice that the private bytes increase but then level off, and the application does not lock up.
Additional query words: mem leak serverside cursor
Keywords: kbado260fix kbbug kbfix KB250315