I am using the following code to connect to database. I can either pass JNDIName or I can provide values for others by leaving JNDI name empty.
If i use JNDI name, it will use a connection from the connection pool of App Server (in my case Weblogic), but it is not releasing the connection after use. Connection remains even if I logoff from the application. If i keep my max connections as 15 in weblogic, after clicking the page with crystal report 15 times all will remain active and users will not be able to login to the application.
If i use connectionString and others without using JNDI Name, it directly connects to database. So it creates a connection in database server directly without using connection pool of weblogic. If i check weblogic, it shows no connection in use as expected, but if i check database, i can see the no. of connections increasing everytime a user clicks a crystal report page.
When the connection touches the maximum allowed connection in server, every application using the same server goes down
How can I close the connection which was created for the viewing the report?
String reportName = "/reports/BankBalance.rpt";
ReportClientDocument clientDoc = (ReportClientDocument) session.getAttribute(reportName);
if (clientDoc == null)
{
clientDoc = new ReportClientDocument();
clientDoc.setReportAppServer(ReportClientDocument.inprocConnectionString);
// Open report
clientDoc.open(reportName, OpenReportOptions._openAsReadOnly);
{
String connectString = ""; // jdbc:sybase:Tds:DBSERVERNAME:9812/DBNAME?ServiceName=DBNAME
String driverName = ""; // com.sybase.jdbc3.jdbc.SybDriver
String JNDIName = "DS_APP";
String userName = "";
String password = "";
// Switch all tables on the main report and sub reports
CRJavaHelper.changeDataSource(clientDoc, userName, password, connectString, driverName, JNDIName);
// logon to database
CRJavaHelper.logonDataSource(clientDoc, userName, password);
}
// Store the report document in session
session.setAttribute(reportName, clientDoc);
}
{
// Create the CrystalReportViewer object
CrystalReportViewer crystalReportPageViewer = new CrystalReportViewer();
String reportSourceSessionKey = reportName+"ReportSource";
Object reportSource = session.getAttribute(reportSourceSessionKey);
if (reportSource == null)
{
reportSource = clientDoc.getReportSource();
session.setAttribute(reportSourceSessionKey, reportSource);
}
// set the reportsource property of the viewer
crystalReportPageViewer.setReportSource(reportSource);
crystalReportPageViewer.setHasRefreshButton(true);
crystalReportPageViewer.setToolPanelViewType(CrToolPanelViewTypeEnum.none);
// Process the report
crystalReportPageViewer.processHttpRequest(request, response, application, null);
}