I am currently on the process of diagnosing connection leaks in my system. I learned from the other programmers that i have to make sure that i am closing all connections i opened whenever i connect the application with the server.

I finally reduced the problem except for one thing. I noticed that everytime i generate a new report on crystal report, a new connection is established. When i close the report, and re-open it. it Still creates a new connections. I can see these since i monitor the connection under the stored procedure sp_who2.

Will this pose a problem on my system performance on connections to the database server?

When i create a report, i first create a stored procedure, link that to my report, create a form and apply these codes: I appreciate any help and information. thanks!


Code:
Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
        'rptsummary.Refresh()
        rptsummary.Load(Application.StartupPath & "\Accounting Reports\report1.rpt")
        Logon(rptsummary, con.Server, con.Database, con.Username, con.password)
        rptsummary.Refresh()
        rptsummary.SetParameterValue("@frmMth", cboMth1.SelectedItem)
        rptsummary.SetParameterValue("@toMth", cboMth2.SelectedItem)

        Me.crvRpt.Visible = True
        Me.crvRpt.ReportSource = rptsummary
    End Sub

    Function Logon(ByVal cr As ReportDocument, ByVal server As String, ByVal db As String, ByVal id As String, ByVal pass As String) As Boolean
        Dim ci As New ConnectionInfo
        Dim subObj As SubreportObject
        ci.ServerName = server
        ci.DatabaseName = db
        ci.UserID = id
        ci.Password = pass
        If Not (ApplyLogon(cr, ci)) Then
            Return False
        End If
        Dim obj As ReportObject
        For Each obj In cr.ReportDefinition.ReportObjects()
            If (obj.Kind = ReportObjectKind.SubreportObject) Then
                subObj = CType(obj, SubreportObject)
                If Not (ApplyLogon(cr.OpenSubreport(subObj.SubreportName), ci)) Then
                    Return False
                End If
            End If
        Next
        cr.Refresh()
        Return True
    End Function

    Function ApplyLogon(ByVal cr As ReportDocument, ByVal ci As ConnectionInfo) As Boolean
        Dim li As TableLogOnInfo
        Dim tbl As Table
        For Each tbl In cr.Database.Tables
            li = tbl.LogOnInfo
            li.ConnectionInfo = ci
            tbl.ApplyLogOnInfo(li)
            If (tbl.TestConnectivity()) Then
                If (tbl.Location.IndexOf(".") > 0) Then
                    tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)
                Else
                    tbl.Location = tbl.Location
                End If
            Else
                Return False
            End If
        Next
        Return True
    End Function