Cannot Open Any more databases



I am converting from ADO to ADO.NET, and have written a routine to get
records from an Access database. It's a customer-order type program. It
works fine until I run a 'batch job' which runs through many orders - I
then get the message "Cannot Open Any more databases" (I presume this
is refering to tables?).

I've tried closing all connections, but it still doesn't work properly.
I don't want to set the connections to nothing if I can avoid it, as
they will then need to be reinitialised each time I call the function
(shown below).

Any help on this would be appreciated!


Function PopDataTable(ByVal ods As DataSet, ByVal sTable As String,
ByVal sSQL As String, Optional ByVal sdsSQL As String = "", Optional
ByVal rowParent As DataRow() = Nothing, Optional ByVal sRelation As
String = "", Optional ByVal bForceClearTable As Boolean = False,
Optional ByVal oda As OleDbDataAdapter = Nothing, Optional ByRef ocn As
OleDbConnection = Nothing, Optional ByVal ocomSel As OleDbCommand =
Nothing) As DataRow()
Dim rowR As DataRow
Dim rowSelected() As DataRow
Dim iRecCount As Integer
Dim iSelCount As Integer
Dim shChildCount As Short
Dim shTabCount As Short

PopDataTable = Nothing

If IsNothing(ocn) Then
'use the generic connection
ocn = cnGen
End If

If IsNothing(ocomSel) Then
'use the generic command object
ocomSel = comSelGen
End If

iSelCount = 0
'See if the rows are there
If Not IsNothing(ods.Tables(sTable)) And Not bForceClearTable
Then
If sdsSQL = "" Then
rowSelected = GetChildren(rowParent, sRelation,
shChildCount)
Else
rowSelected = ods.Tables(sTable).Select(sdsSQL)
End If
iSelCount = rowSelected.Length
PopDataTable = rowSelected
ElseIf Not IsNothing(ods.Tables(sTable)) And bForceClearTable
Then
'Clear the dataset if necessary or required
ods.Tables(sTable).Clear()
End If

'if there are no records execute query
If iSelCount = 0 Then
Try
ocn.Open()

'Set the SelectCommand string and connection...
ocomSel.CommandText = sSQL
ocomSel.Connection = ocn

'set the data adapter to use this information
oda.SelectCommand = ocomSel

'Fill the dataset table
iRecCount = oda.Fill(ods, sTable)
shTabCount = ods.Tables.Count()
If iRecCount > 0 Then
If sdsSQL <> "" Then
PopDataTable =
ods.Tables(sTable).Select(sdsSQL)
Else
'If there's no relationship, select the whole
datatable
'as it's just been populated
If RelationShipExists(ods, sRelation) Then
'PopDataTable = GetChildren(rowParent,
sRelation, shChildCount)
PopDataTable =
ods.Tables(sTable).Select(sdsSQL)
Else
PopDataTable =
ods.Tables(sTable).Select(sdsSQL)
End If
End If
End If

Catch eFillException As System.Exception
MsgBox(eFillException.ToString)
'TODO: handle errors here
Finally
ocomSel.Connection.Close()
ocomSel.Connection.ReleaseObjectPool()
oda.SelectCommand.Connection.Close()
oda.SelectCommand.Connection.ReleaseObjectPool()
ocn.Close()
End Try
End If
Return PopDataTable
End Function

.



Relevant Pages

  • Re: Send Message to filemaker 5.5 from windows form application
    ... Script created by Steve Carson and it was modified by Kristina ... ' Chrto represent double quotes if you are passing a string. ... Dim pHyperlink As IHyperlink ... 'opens Microsoft Access database ...
    (comp.databases.filemaker)
  • Re: Join DataTables in same dataset
    ... I needed to import an Excel spreadsheet into an access database. ... create OleDbConnection to the Access DataBase. ... have different schemas. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: email report per record
    ... is a couple of Access database ... Dim strSubject As String 'Email Subject ... Dim stDocName As String ...
    (microsoft.public.access.reports)
  • Network user count question
    ... an MS Access database on a network server? ... Public Function AddUser(mUserID As String, ... Dim bOK As Boolean ... Dim obj As User ...
    (microsoft.public.vb.database.ado)
  • Re: Amend Access database from Excel
    ... The code below uses ADO to connect to the Access database. ... The query string ... Dim oConn As ADODB.Connection ... Set oConn = New ADODB.Connection ...
    (microsoft.public.excel.programming)