Solved

ADODB.recordset rss = Nothing, neccesary ?

Posted on 2004-10-19
1
169 Views
Last Modified: 2010-04-23
   Public Function isVacationOverLap(ByVal empl As Employee, ByVal sDate As Date, ByVal eDate As Date, Optional ByVal vID As Integer = 0)
        Dim rss As New ADODB.Recordset
        Dim sqlStr As String = "select startDate from vacation
       rss.Open(sqlStr, DBConnection.getInstance, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
        If rss.EOF Then
            rss.Close()
            rss = Nothing
            Return False
        Else
            rss.Close()
            rss = Nothing
            Return True
        End If
    End Function

Hi is it at all necessary to do something like
rss = Nothing
or do i need to do an rss.close ?

Iam programming webParts in VB.net and currently iam having trouble with my webParts building up the w3wp process and sql server process and using more than 80 MB of ram on each of them and running at high processor cost, resulting in slow loading times for the WebParts.

Can someone tell me how to make sure the Recordset close down right, iam using an DBConnection class which uses singleton principle

Public Class DBConnection
    Private Shared con As DBConnection
    Private Shared DBCon As ADODB.Connection
    Private Sub New()
        DBCon = New ADODB.Connection
        DBCon.Open("driver={SQL Server};server=agportal;database=agportal")
    End Sub
    Public Shared Function getInstance() As ADODB.Connection
        If con Is Nothing Then
            con = New DBConnection
            Return DBCon
        Else
            Return DBCon
        End If
    End Function
End Class

0
Comment
Question by:mSchmidt
1 Comment
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 500 total points
ID: 12346220
while not strictly NECESSARY, it is generally a good style to set all 'expensive' resources, such as recordsets and connections to Nothing explicitly.  That makes you code somewhat more 'self-documenting' so that someone else understands that you are clkearing the variables when they are no longer needed.  A purist will argue that the local variable will be set to Nothng when it goes out of scope (at the End  Function, in your case) and that is why I said that it is not NECESSARY to set rss to Nothing.  I guess old habits die hard.

ps.

by the way, your function can be made a bit cleaner:

 Public Function isVacationOverLap(ByVal empl As Employee, ByVal sDate As Date, ByVal eDate As Date, Optional ByVal vID As Integer = 0)
        Dim rss As New ADODB.Recordset
        Dim sqlStr As String = "select startDate from vacation... " ' you need a Where clause here!!!
        rss.Open(sqlStr, DBConnection.getInstance)
        Return Not rss.Eof
    End Function

AW
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now