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:
Try 'Loop through each table in the report and set the connection info crTables = crReportDocument.Database.Tables For Each crTable In crTables crtableLogoninfo = crTable.LogOnInfo crtableLogoninfo.ConnectionInfo = crConnectioninfo crTable.ApplyLogOnInfo(crtableLogoninfo) Next Catch ex As Exception MsgBox("Unable to Log On To report Tables", MsgBoxStyle.Critical) MsgBox("Loading of " & strReportName & " Cancelled.", MsgBoxStyle.Information) 'MsgBox(ex.ToString) GoTo StopHere End Try Try ' Loop through each section and find report objects crSections = crReportDocument.ReportDefinition.Sections For Each crSection In crSections crReportobjects = crSection.ReportObjects For Each crReportobject In crReportobjects If crReportobject.Kind = ReportObjectKind.SubreportObject Then ' If a subreport is found cast as subreportobject crSubReportobject = CType(crReportobject, SubreportObject) ' Open the sub report subReportDocument = crSubReportobject.OpenSubreport(crSubReportobject.SubreportName) crDatabase = subReportDocument.Database crTables = crDatabase.Tables ' Loop through each table in the sub report and set the connection info For Each crTable In crTables crtableLogoninfo = crTable.LogOnInfo crtableLogoninfo.ConnectionInfo = crConnectioninfo crTable.ApplyLogOnInfo(crtableLogoninfo) Next End If Next Next Catch ex As Exception MsgBox("Unable to Log On To Sub Report Tables") ' MsgBox(ex.ToString) End Try




Reply With Quote