Solved

ADODB.recordset rss = Nothing, neccesary ?

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net 2 43
Vb.net dynamic formulas in runtime 11 75
VS.net 2010 11 36
How do sunrise and sunset times change with altitude 14 31
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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