Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Reports connection to Access DB not releasing 1

Status
Not open for further replies.

FarleySoftware

Programmer
Jan 14, 2008
18
0
0
US
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:

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.
 
No, unfortunately ... LDB persists until the application itself closes.

Neither does this (thought I'd try to "undo" the connection):

Code:
            For Each crTable In crReportDocument.Database.Tables
                crTable.Dispose()
            Next
 
Thanks! I have been pulling my hair out since yesterday and this solved my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top