Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 897817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:56:36+00:00 2026-05-15T14:56:36+00:00

I am using Access 2003 to access data stored in a SQL Server database

  • 0

I am using Access 2003 to access data stored in a SQL Server database via ADO. Most often I obtain the data using stored procedures. I execute the stored procedures via ADO in a separate function that returns a recordset. When returning a recordset from a function where is the best place to close the recordset and release it’s hold on memory? Is it done in the function that returns the recordset or is it done in the sub/function that calls the function executing the ADO code? Here is an example …

Here is the calling method

Public Sub CallingMethod()
  Dim rs As ADODB.Recordset
  Set rs = GetDataFromDatabase()
  Set myListBox.Recordset = rs
  rs.Close
  Set rs = Nothing
End Sub

Here is the Method that actually executes the stored procedure and returns it to the calling method

Public Function GetDataFromDatabase()
  Dim cnn As ADODB.Connection
  Dim rs As ADODB.Recordset

  Set cnn = New ADODB.Connection
  cnn.ConnectionString = myConnectionString
  cnn.Open

  Set rs = New ADODB.Recordset
  Set rs.ActiveConnection = cnn
  rs.Source = "EXEC uspMyStoredProcedure"

  rs.LockType = adLockOptimistic
  rs.CursorType = adOpenStatic
  rs.CursorLocation = adUseClient
  rs.Open

  Set GetDataFromDatabase = rs

  Set rs = Nothing
  Set cnn = Nothing

End Function

What I am wondering is where I should be closing the recordset and setting it equal to nothing. Am I doing it in both places without needing to? Just looking for best practices. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:56:37+00:00Added an answer on May 15, 2026 at 2:56 pm

    I’m not sure what’s proper, either. I tried an approach where the calling code creates the connection object and passes it to the function. The caller is responsible for disposing of both the connection and recordset objects. It’s quick & dirty because I didn’t want to invest more in it only to find out my approach is just plain boneheaded.

    Public Sub test_GetDataFromSP()
        Dim cnn As ADODB.Connection
        Dim rs As ADODB.Recordset
    
        Set cnn = New ADODB.Connection
        cnn.ConnectionString = "DRIVER=SQL Server;SERVER=VM2003\SQLEXPRESS;" & _
            "Trusted_Connection=Yes;DATABASE=Inventory"
        cnn.Open
        Set rs = GetDataFromSP("GetCenterCodes", cnn, "14, 14, 501")
        rs.MoveLast
        Debug.Print rs.RecordCount
        rs.Close
        Set rs = Nothing
        cnn.Close
        Set cnn = Nothing
    End Sub
    
    Public Function GetDataFromSP(ByVal pProc As String, _
        ByRef pConnection As ADODB.Connection, _
        Optional ByVal pArguments As String) As ADODB.Recordset
    
        Dim rs As ADODB.Recordset
        Dim strStatement As String
    
        strStatement = "EXEC " & pProc
        If Len(pArguments) > 0 Then
            strStatement = strStatement & " " & pArguments
        End If
        strStatement = strStatement & ";"
        Set rs = New ADODB.Recordset
        Set rs.ActiveConnection = pConnection
        rs.Source = strStatement
        rs.LockType = adLockOptimistic
        rs.CursorType = adOpenStatic
        rs.CursorLocation = adUseClient
        rs.Open
        Set GetDataFromSP = rs
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Access 2003 project in which all data is stored in SQL
Using VB.NET with ASP.NET and and ms-access 2003 data, I'm trying to input data
I'm using an MS Access 2003 front end to access the data on a
Using Access 2003 Database Table1 Intime Outtime WorkTime OverTime 08:00:00 19:00:00 09:00:00 02:00:00 09:00:00
I have some data stored in SQL Server that contains apostrophes. Within the SQL
I am trying to access the data from MS Access Database using C#. in
I am on a windows server 2003 and accessing a locally stored MS Access
I am upsizing an MS Access 2003 app to a SQL Server backend. On
Using Access 2003 Database Table EmpID Intime Outtime 001 090020 180000 002 060000 220000
I inherited an access 2003 ADP file which uses sql 2000 as it's data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.