Our VB6 application works with multiple MS-Access databases which represent different resultsets. When the user selects a resultset, the database that contains the resultset is renamed to Temp.mdb for the time the user needs its data. When the user is done the Temp.mdb is renamed to its original name. (Please accept this design, there was a good reason for it at the time).
A pitfall of this design is, that when there is an open connection to the Temp.mdb the rename fails with a permission denied error. So in our code all connections are meticulously closed beforehand.
Enter Crystal reports:
We create a report using CraxDRT.Application.OpenReport(path), pass it around some Net dll’s to set its parameters and then send it to the CRViewer or the printer. After this it seems that the report keeps lingering around and keeps an open connection the the Temp.mdb, thereby write protecting the temp.ldb. I tried to set all references tot the report within Vb6 and Net to null/Nothing, but the report itself has no IDispose interface, Close method or whatever. Only when I close the main application the connection to the database disappears. After restarting I can then rename it.
There must be a way to release the lock that the report holds on the Temp.ldb file so that I can rename the Temp.mdb. But how??
PS: The strange thing is that when I call up a different report that uses the same data, but that is not passed to Net dll’s, in some way or another the lingering report is garbage collected and it releases its lock too.
If it’s not garbage collection issue then it’s probably connection pooling by .NET/OLEDB provider CR is using. Though usually it is not enabled for JET databases.
You can wrap your reporting logic in a separate executable that launches CR viewer or prints report and then exits effectively forcing GC and/or clearing open connections.