Solved

ADODB.recordset rss = Nothing, neccesary ?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

688 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