By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 2,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

Cannot close connection of crystal report

P: n/a
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_c58d 8a47-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.Tab le crTable in
crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}

foreach(CrystalDecisions.CrystalReports.Engine.Tab le 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;
}
}
}

Jan 13 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.