FarleySoftware
Programmer
I have a CrystalReportViewer in a form, with data coming from an Access DB.
The source report of the CrystalReportViewer is selected from a drop-down list
Everything displays fine.
However, once the form containing the CrystalReportViewer closes, the Access DB connection remains (.LDB file continues to exist). This poses a problem, as the app calls a routine to compact the Access DB upon closing, which of course cannot happen if there's still a lock on it. Plus it's not "clean" programming to leave something hanging IMO.
Here's my code for setting the report and establishing the database connection:
What code is used to break the connection to the Access DB?
Thanks in advance. Hope I've been clear on what's happening.
The source report of the CrystalReportViewer is selected from a drop-down list
Everything displays fine.
However, once the form containing the CrystalReportViewer closes, the Access DB connection remains (.LDB file continues to exist). This poses a problem, as the app calls a routine to compact the Access DB upon closing, which of course cannot happen if there's still a lock on it. Plus it's not "clean" programming to leave something hanging IMO.
Here's my code for setting the report and establishing the database connection:
Code:
Dim strReportName As String = cboReport.SelectedValue
Dim crReportDocument As New ReportDocument
Dim crConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
Dim crTableLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
crReportDocument.Load(strReportPath)
Dim strPath As String = GetPreferenceToolkitPath()
With crConnectionInfo
'.DatabaseName = strpath 'If you are connecting to Access through ODBC, then set the 'DatabaseName' for the ConnectionInfo' object as follows:
.ServerName = strPath 'If you are connecting to Access through OLE DB, then set set the 'ServerName':
'.UserID = "Admin"
.Password = "Password"
End With
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables
For Each crTable In crReportDocument.Database.Tables
crTableLogonInfo = crTable.LogOnInfo
crTableLogonInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogonInfo)
Next
CrystalReportViewer1.ReportSource = crReportDocument
CrystalReportViewer1.RefreshReport()
What code is used to break the connection to the Access DB?
Thanks in advance. Hope I've been clear on what's happening.