Symptom
- The Oracle database connections remain open when InProc RAS sdk method GetLastPageNumber() is used in the application.
- When CrystalReportViewer is used, the database connections get closed irrespective of the GetLastPageNumber()
Environment
- Visual Studio 2008
- Crystal Reports 2008 SP06
- Oracle database
- Odbc connection
Reproducing the Issue
1. Create a Windows application to load a Crystal report, which is connected to a Oracle database using Odbc connection.
2. Following is the code used to load the report:
rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string reportPath = Application.StartupPath + "\\" + "ORACLE1_TEST.rpt";
rd.Load(reportPath);
CrystalDecisions.Shared.ConnectionInfo boConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
boConnectionInfo.ServerName = "orcl";
boConnectionInfo.UserID = "system";
boConnectionInfo.Password = "Password#123";
foreach (CrystalDecisions.CrystalReports.Engine.Table boTable in rd.Database.Tables)
{
CrystalDecisions.Shared.TableLogOnInfo boTableLogOnInfo = boTable.LogOnInfo;
boTableLogOnInfo.ConnectionInfo = boConnectionInfo;
boTable.ApplyLogOnInfo(boTableLogOnInfo);
}
rcd = new ReportClientDocumentClass();
rcd = rd.ReportClientDocument;
rcd.ReportSource.GetLastPageNumber(new CrystalDecisions.ReportAppServer.ReportDefModel.RequestContext());
//On a seperate Close button click, the close, dispose methods are called:
rd.Close();
rd.Dispose();
rcd.Close();
3. Execute the application.
4. Click on the Close button.
5. Check for the database connections from the SQL Plus.
6. The connections are still seen open.
Cause
After the application is closed, the object is not released by the .net runtime.
Resolution
After adding the GC.Collect() in the Close button method, the connections are released:
rcd.Close();
rcd = null;
rd.Close();
rd.Dispose();
rd = null;
GC.Collect();
GC.WaitForPendingFinalizers();
Keywords
database connections, database connections remain open, Oracle database, GetLastPageNumber(), CrystalReportViewer , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem