artee 0 Newbie Poster

I get the following error
"Timeout expired. the timeout period elapsed prior to obtaining a connection from the pool. this may have occurred because all pooled connections were in use and max pool size was reached."

The below code is in the click event of the Upload button. This works fine when it is executed the first time (for loop, loops thru around 100 records). However, when I click the button the second time, it displays the above error after looping around 6 to 8 times.

As far as I know, I am closing the connection.
What am I doing wrong?
Please help
- Artee

Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Dim con As New ConnectClass
Dim myConnect As String
Dim cmdString As String
Dim i As Integer, j As Integer
Dim ds1 As New DataSet
Dim dv2 As New DataView
ds1.Merge(mCSV.CSVDataSet.Tables(0).Copy)
ds1.Clear()
 
 
dv2 = New DataView(ds1.Tables(0))
For i = 0 To mCSV.CSVDataSet.Tables(0).DefaultView.Count - 1
 
 
cmdString = " Select * from SCHDB.dbo.DistrictAll " & _
" where DCode = '" & dgrdView1.Item(i, 0) & "'" 
 
Dim da As New SqlDataAdapter(cmdString, con.GetDBConnection)
If da.SelectCommand.ExecuteReader.HasRows = False Then
Else
 
Dim drv As DataRowView = dv2.AddNew
For j = 0 To 13
drv(ColNameCheck(j)) = dgrdView1.Item(i, j)
Next
End If
 
da.Dispose()
con.GetDBConnection.Dispose()
 
Next
dgrdUploadedAll.DataSource = dv2
con.GetDBConnection.Close()
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.