Incorrect Log on Parameters... using DataSet as report source
I have a class that returns a dataset of records I want to display in a CR. Getting the data works, I tested this with a simple GridView.
When I bind the dataset to my report I get get the following error:
Logon failed. Details: crdb_adoplus : Object reference not set to an instance of an object. Error in File C:\DOCUME~1\JMeckley\LOCALS~1\Temp\OverallSummary {DDFCFE37-4903-49DD-B70E-C2D9C07ABE11}.rpt: Unable to connect: incorrect log on parameters.Why would I receive this error? There are no DB parameters for the report. It's based on a DataSet. Any ideas on how to fix this?
This is my aspx tag:
<CR:CrystalReportViewer ID="rptviewer" runat="server" AutoDataBind="true" EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" ReuseParameterValuesOnRefresh="True" />This is my code behind.
private string _report_name;
private string _report_path
{
//check to make sure the report exists.
get
{
string path = string.Format("~/Reports/{0}.rpt", this._report_name);
if (!System.IO.File.Exists(Server.MapPath(path)))
{
//log invalid report path
essage.Visible = true;
return string.Empty;
}
else
return Server.MapPath(path);
}
}
//I can't get this to work as a property so i'm creating a function to set the value instead.
private void set_report_name(string val)
{
//validate report is not empty string and only contains alphanumerics or underscore
if (val == string.Empty)
{
//log missing report name
message.Visible = true;
this._report_name = string.Empty;
}
else if (!STR.Regex.IsMatch(val, @"^[A-Za-z0-9_]+$"))
{
//log invalid report name
message.Visible = true;
this._report_name = string.Empty;
}
else
this._report_name = Server.HtmlEncode(val);
}
protected void Page_Init(object sender, EventArgs e)
{
//encode report_name to reduce script highjacking
this._report_name = Server.HtmlEncode(Request.QueryString["report_name"]);
this.prepareReport2();
rptviewer.ReportSource = this._report;
}
private void prepareReport2()
{
this._report = new CCE.ReportDocument();
this._report.Load(this._report_path);
DataSet dataset = SAD.DataAccessLayer.OverallSummary(2005);
this._report.SetDataSource(dataset);
}
Answers
I found the solution at http://aspalliance.com/490
KL left a comment on the post that solved the problem.
If your dataset has only one table, then the ReportDocument.SetDataSource() should be passed a DataTable object.
If your dataset has multiple tables that are linked, then ReportDocument.SetDataSource() should be passed a DataSet object.
All Replies
I found the solution at http://aspalliance.com/490
KL left a comment on the post that solved the problem.
If your dataset has only one table, then the ReportDocument.SetDataSource() should be passed a DataTable object.
If your dataset has multiple tables that are linked, then ReportDocument.SetDataSource() should be passed a DataSet object.HI!!!!
I only have one row in my table, and one table in my dataset, an i been haven the error
La conexión no es posible.
Detalles: crdb_adoplus : Referencia a objeto no establecida como instancia de un objeto.
Error en archivo C:\DOCUME~1\SANCHE~1\CONFIG~1\Temp\crProyectoIndividual {8E72BC6E-C359-406E-8A7E-A81005D52FA0}.rpt:
No se puede conectar: parámetros de conexión incorrectos.But now i put the setdatasource(TABLA) an everything works fine..... tanks very very very very ver very much
- I'm with the same problem, but in "c #"
I'm not pointing the "User" nor the "Password" of the report.
I'm not using "DataSets"
do you can help me?
thanks! Hi,
I got the answer for this Error after a long work out.
1. If U have Sub report in your report it should be binded with the Data
2. If the Sub Report is not binded with the Data then don't do Report.SetLogonInfo=False;
Just try this code in C# it is using a Sub report...
ReportDocument
oReport = new ReportDocument(); ReportDocument SubRpt = new ReportDocument(); public DataAccessLayerBaseClass dataAccess; DataSet ds = new DataSet();CatalogTableAdapters.
CatalogTableAdapter daCatalog = new CatalogTableAdapters.CatalogTableAdapter(); Catalog.CatalogDataTable Catalog = new Catalog.CatalogDataTable();try
{
ds = GenerateCutQtyReport(Request.QueryString[
"WhereStr"]);oReport.Load(Server.MapPath(
"MyReport.rpt")); if (ds.Tables[0].Rows.Count > 0){
oReport.SetDataSource(ds);
SubRpt = oReport.OpenSubreport(
"MySubReport");SubRpt.SetDataSource((System.Data.
DataTable)Catalog);}
else{
throw new Exception("No Records to Display.");}
oReport.SetParameterValue(
"PageHeading1", Request.QueryString["PH1"]);oReport.SetParameterValue(
"PageHeading2", Request.QueryString["PH2"]);CrystalReportViewer1.ReportSource = oReport;
CrystalReportViewer1.DisplayGroupTree =
false;CrystalReportViewer1.DataBind();
}
catch (System.Exception ex){
lblError.Text += ex.Message;
}
finally{
oReport =
null;}
Thanks a Lot...
Happy Coding All
Regards
Iyyappan.A
Adds the table ".tables(x)"
this._report.SetDataSource(dataset.tables(0));
Thank's a lot Helio.Pedro !
I was with the same problem. The message Logon Failed in Crystal Reports.i put the index of my table in a DataSet and solved the problem.
- Proposed As Answer bynisipop Monday, January 18, 2010 1:09 PM