Cannot close connection of crystal report


B

bonita

In my ASP.NET page, I have 2 checkboxes for users to choose which
crystal report they want to display. These two reports use different
tables. If report1 has been choosen and displayed in the crystal
report, then I cannot check another checkbox to display report2
afterwards. If I close the website and open again, I can choose report2
and display as crystal report correct, but now I cannot check the
checkbox1 to display report 1 afterwards.
This is the error message:

Error in File
C:\DOCUME~1\CHRISHO\ASPNET\LOCALS~1\Temp\temp_c58d8a47-521f-4540-bf93-d4f493584892.rpt:
Error in formula <Record_Selection>. '{INUTMTI_TERM.part_user} =
{?in_user} and ' This field name is not known.


The table INUTMTI_TERM is the table used by report 1, not by report 2,
but it's trying to access this table when I choose to display report2.
Although I try to close the report in the Page_Unload() method, somehow
the crystal report connection would not close and cause this problem.
I'm attaching my code here (some code deleted to improve readability).
Please give me some hint on how to solve this problem.

Thanks,
Christine


namespace inventory
{

public class userreqterm : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer
CrystalReportViewer1;
userreqtermCR crReportDocument;
userreqtermWCR crReportDocument2;
TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
TableLogOnInfo crTableLogOnInfo2 = new TableLogOnInfo();
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Database crDatabase2;
CrystalDecisions.CrystalReports.Engine.Tables crTables2;


private void Page_Load(object sender, System.EventArgs e)
{
crReportDocument = new userreqtermCR();
crReportDocument2 = new userreqtermWCR();
crConnectionInfo.ServerName = "x.x.x.x";
crConnectionInfo.DatabaseName = "xxxx";
crConnectionInfo.UserID = "xxxx";
crConnectionInfo.Password = "xxxx";
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;
crDatabase2 = crReportDocument2.Database;
crTables2 = crDatabase2.Tables;

foreach(CrystalDecisions.CrystalReports.Engine.Table crTable in
crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}

foreach(CrystalDecisions.CrystalReports.Engine.Table crTable2 in
crTables2)
{
crTableLogOnInfo2 = crTable2.LogOnInfo;
crTableLogOnInfo2.ConnectionInfo = crConnectionInfo;
crTable2.ApplyLogOnInfo(crTableLogOnInfo2);
}
}

private void Page_Unload(object sender, System.EventArgs e)
{
crReportDocument.Close();
crReportDocument.Dispose();
crReportDocument2.Close();
crReportDocument2.Dispose();
crReportDocument = null;
crReportDocument2 = null;
crTableLogOnInfo = null;
crTableLogOnInfo2 = null;
crConnectionInfo=null;
crDatabase =null;
crTables = null;
crDatabase2 = null;
crTables2 = null;
CrystalReportViewer1.Dispose();
CrystalReportViewer1 = null;
}


private void run_Click(object sender, System.EventArgs e)
{
SqlCommand command = new SqlCommand("inutmti_upd_chrg",connection);
command.Connection=connection;
command.CommandType=CommandType.StoredProcedure;
command.CommandText = "inutmti_upd_chrg";
command.Parameters.Add(new
SqlParameter("@in_user",SqlDbType.VarChar, 5));
command.Parameters["@in_user"].Value=department.SelectedValue.ToString();
command.Parameters.Add(new
SqlParameter("@in_yyyymmdd",SqlDbType.DateTime, 8));
command.Parameters["@in_yyyymmdd"].Value=termenddate.Text.ToString();
connection.Open();
command.ExecuteNonQuery();
connection.Close();

ParameterFields paramFields = new ParameterFields();
ParameterField user = new ParameterField();
ParameterField dept = new ParameterField();
ParameterField yyyymmdd = new ParameterField();
ParameterDiscreteValue dcuser = new ParameterDiscreteValue();
ParameterDiscreteValue dcdept = new ParameterDiscreteValue();
ParameterDiscreteValue dcyyyymmdd = new ParameterDiscreteValue();

dept.ParameterFieldName = "in_dept";
dcdept.Value = department.SelectedItem.Text.ToString();
dept.CurrentValues.Add(dcdept);

user.ParameterFieldName = "in_user";
dcuser.Value = department.SelectedValue.ToString();
user.CurrentValues.Add(dcuser);

yyyymmdd.ParameterFieldName = "in_yyyymmdd";
dcyyyymmdd.Value = termenddate.Text.ToString();
yyyymmdd.CurrentValues.Add(dcyyyymmdd);

paramFields.Add(user);
paramFields.Add(dept);
paramFields.Add(yyyymmdd);

if(option.SelectedValue.ToString()=="L")
{
CrystalReportViewer1.ReportSource = crReportDocument;
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.Visible=true;
CrystalReportViewer1.DataBind();

}
else if(option.SelectedValue.ToString()=="W")
{
CrystalReportViewer1.ReportSource = crReportDocument2;
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.Visible=true;
CrystalReportViewer1.DataBind();

}

crTableLogOnInfo = null;
crTableLogOnInfo2 = null;
crConnectionInfo=null;
crDatabase =null;
crTables = null;
crDatabase2 = null;
crTables2 = null;
}
}
}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top