Cannot Open Any more databases
- From: pr_Adams@xxxxxxxxx
- Date: 26 May 2005 09:14:20 -0700
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
.
- Prev by Date: Re: Join on two data tables in same dataset
- Next by Date: DataGrid.DataSource undefined when trying to Sort
- Previous by thread: Data Table Joins
- Next by thread: DataGrid.DataSource undefined when trying to Sort
- Index(es):
Relevant Pages
|