closing connections
- From: "11Oppidan" <11Oppidan@xxxxxxxxxxxxxxxx>
- Date: Sun, 5 Jun 2005 16:44:14 +0100
Hi,
I have a VB .NET program that uses ADO SqlClient dataadapters and MS SQLS.
It uses the Master db to return the names of attached databases, and then
connects to each one to check whether it is a specific type of database or
not by looking for a specific table (any ideas of a better way to do this
would be welcomed).
The problem I am having is closing my connections. Despite the fact that I
explicitly close and dispose each connection (see code below), the number of
connections as measured in SQLServer:GeneralStatistics - 'User connections'
in SQL Server Profiler keeps growing. The user connections only seem to
close when I close my app. This is a problem as in some case we have over
1000 databases on the server. How do I ensure that these connections are
always closed?!
Any assistance/thoughts much appreciated.
Dim cnn As SqlConnection = New SqlConnection(strcnn)
Dim adpSQLS As SqlDataAdapter = New SqlDataAdapter
Dim cmd As SqlCommand = New SqlCommand(strSQL, cnn)
Try
cmd.CommandTimeout = 10000
adpSQLS.SelectCommand = cmd
cnn.Open()
adpSQLS.Fill(dst, strdtbName)
Return dst.Tables(strdtbName)
Catch expSql As SqlException
UI.WriteErrorLogs("PopulateDataset", expSql)
Finally
If Not cnn Is Nothing Then cnn.Close()
If Not cnn Is Nothing Then cnn.Dispose()
If Not adpSQLS Is Nothing Then adpSQLS.Dispose()
If Not cmd Is Nothing Then cmd.Dispose()
End Try
.
- Follow-Ups:
- Re: closing connections
- From: 11Oppidan
- Re: closing connections
- Prev by Date: Re: ADO recordset object's underlying command text
- Next by Date: Re: closing connections
- Previous by thread: SQL Image to rich text box (Cross posted to microsoft.public.dotnet.languages.vb)
- Next by thread: Re: closing connections
- Index(es):
Relevant Pages
|