Hi,

I've built and rolled out an app that contains a Crystal Reports Viewer for reporting purposes which connects to a Db on a SQL Server. The code I'm using to connect is below.

The problem I'm having is everytime the user opens a new or different report they are opening a new process on the server which is causing performance issues.

Can anyone tell me how I can close the connection each time the load report has been completed.

Thanks

VB Code:
  1. Try
  2.             'Loop through each table in the report and set the connection info
  3.             crTables = crReportDocument.Database.Tables
  4.             For Each crTable In crTables
  5.                 crtableLogoninfo = crTable.LogOnInfo
  6.                 crtableLogoninfo.ConnectionInfo = crConnectioninfo
  7.                 crTable.ApplyLogOnInfo(crtableLogoninfo)
  8.             Next
  9.         Catch ex As Exception
  10.             MsgBox("Unable to Log On To report Tables", MsgBoxStyle.Critical)
  11.             MsgBox("Loading of " & strReportName & " Cancelled.", MsgBoxStyle.Information)
  12.  
  13.             'MsgBox(ex.ToString)
  14.  
  15.             GoTo StopHere
  16.         End Try
  17.  
  18.         Try
  19.             ' Loop through each section and find report objects
  20.             crSections = crReportDocument.ReportDefinition.Sections
  21.             For Each crSection In crSections
  22.                 crReportobjects = crSection.ReportObjects
  23.                 For Each crReportobject In crReportobjects
  24.                     If crReportobject.Kind = ReportObjectKind.SubreportObject Then
  25.                         ' If a subreport is found cast as subreportobject
  26.                         crSubReportobject = CType(crReportobject, SubreportObject)
  27.                         ' Open the sub report
  28.                         subReportDocument = crSubReportobject.OpenSubreport(crSubReportobject.SubreportName)
  29.                         crDatabase = subReportDocument.Database
  30.                         crTables = crDatabase.Tables
  31.                         ' Loop through each table in the sub report and set the connection info
  32.                         For Each crTable In crTables
  33.                             crtableLogoninfo = crTable.LogOnInfo
  34.                             crtableLogoninfo.ConnectionInfo = crConnectioninfo
  35.                             crTable.ApplyLogOnInfo(crtableLogoninfo)
  36.                         Next
  37.                     End If
  38.                 Next
  39.             Next
  40.         Catch ex As Exception
  41.             MsgBox("Unable to Log On To Sub Report Tables")
  42.             ' MsgBox(ex.ToString)
  43.  
  44.         End Try