Error 3048: Cannot Open Any More Databases

TimTDP

Registered User.
Local time
Today, 18:08
Joined
Oct 24, 2008
Messages
213
I am using Access 2010

I am suddenly getting the error 3048: Cannot open any more databases

The error occurs on the line of code: Set db = CurrentDb()

Code:
Private Sub SetInUseFalse(TelesalesId As Long)
  
  Dim db As DAO.Database
  Dim rst As DAO.Recordset
  
  Set db = CurrentDb()
  Set rst = db.OpenRecordset("Select InUseBy from tblTelesales where Telesalesid = " & TelesalesId)
  
  Run Some Code
  
  CloseRecordSet rst
  SetObjectToNothing db
End Sub
I always open recordsets as coded above, and close them as coded below.

Code:
 Public Sub CloseRecordSet(RecordsetName)
  
  On Error GoTo Err_Handler
  
  If Not RecordsetName Is Nothing Then
      RecordsetName.Close
      Set RecordsetName = Nothing
      GoTo Exit_Sub
  End If
  
  Exit_Sub:
      Exit Sub
  
  Err_Handler:
      Select Case Err.Number
          Case 0
              Resume Exit_Sub
                  
          Case 3420
              Resume Exit_Sub
          
          Case Else
              MsgBox Err.Number & " - " & Err.Description
              Resume Exit_Sub
      End Select
      
  End Sub
Code:
Public Sub SetObjectToNothing(ObjectName)
  
  On Error GoTo Err_Handler
  
  If Not ObjectName Is Nothing Then
      Set ObjectName = Nothing
  End If
  
  Exit_Sub:
      Exit Sub
  
  Err_Handler:
      Select Case Err.Number
          Case 0
              Resume Exit_Sub
                  
          Case 9126
              Resume Exit_Sub
          
          Case Else
              MsgBox Err.Number & " - " & Err.Description
              Resume Exit_Sub
      End Select
  
  End Sub
Why should I suddenly get this error? The error appears to be in a loop. If I close the error message, it pops up again. I have to close the database using Windows Task Manager.

Is there a maximum number of connections? But I religiously close connections as indicated above!
I am only connecting to the current database (backend form frontend)
Am I opening / closing connections & recordsets correctly?
 
Your code seems to be OK.
I encountered this error when I run queries with subqueries and, by mistake, I have a cycle in this structure.
 
You don't need to call a subroutine to close a recordset, or to set an object variable to nothing. You could simplify your code to . . .
Code:
Private Sub SetInUseFalse(TelesalesId As Long)
   With CurrentDb.OpenRecordset("Select InUseBy from tblTelesales where Telesalesid = " & TelesalesId)
      Run Some Code
      .Close
   End With
End Sub
. . . with no adverse impact. The recordset is closed in the routine in which it is opened. That is acceptable, and far simpler.

And yes, there is a limit to how many database variables you can create, so if you create one in a loop--particularly a recursive loop--you will eventually run out. What are you trying to do that you need to open so many connections to the database?
 
Thanks lagbolt
What are you trying to do that you need to open so many connections to the database?
I don't know!
The front-end is obviously connected to the back-end.
I never have more than 5 recordsets open. I always close them when I am finished with them
Is there a limit to the number of queries that a database can have?
 
Found the problem!
I had an endless loop in my code
Code:
Private Sub SetInUseFalse(TelesalesId As Long)
 
 Dim db As DAO.Database
 Dim rst As DAO.Recordset
 
 If IsNull(TelesalesId) Then Exit Sub
 
 Set db = CurrentDb()
 Set rst = db.OpenRecordset("Select InUseBy from tblTelesales where Telesalesid = " & TelesalesId)
 If rst.RecordCount > 0 Then
     If rst!InUseBy = pubUserID Then
         SetInUseFalse TelesalesId  <===========
     End If
 End If
 
 CloseRecordSet rst
 SetObjectToNothing db
 
 End Sub
I have marked the error with <===========

Thanks to all who helped
 

Users who are viewing this thread

Back
Top Bottom