?
Solved

ADODB.recordset rss = Nothing, neccesary ?

Posted on 2004-10-19
1
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 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