Solved

ADODB.recordset rss = Nothing, neccesary ?

Posted on 2004-10-19
1
167 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

12 Experts available now in Live!

Get 1:1 Help Now