Click here to Skip to main content
15,666,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
getting error when i execute the below code

protected void Button1_Click1(object sender, EventArgs e)
{
//Instantiate variables
ReportDocument reportDocument = new ReportDocument();
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

//Set instances for input parameter 1 - @vDepartment
paramField.Name = "depart_name";
//Below variable can be set to any data
//present in SalseData table, Department column
paramDiscreteValue.Value = "South";
paramField.CurrentValues.Add(paramDiscreteValue);
//Add the paramField to paramFields
paramFields.Add(paramField);



/* //Set instances for input parameter 2 - @iSalseYear
//*Remember to reconstruct the paramDiscreteValue and paramField objects
paramField = new ParameterField();
paramField.Name = "@iSalesYear";
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = "2004";
paramField.CurrentValues.Add(paramDiscreteValue);

//Add the paramField to paramFields
paramFields.Add(paramField);*/

CrystalReportViewer4.ParameterFieldInfo = paramFields;

reportDocument.Load(Server.MapPath("CrystalReport4.rpt"));

//set the database loggon information.
//**Note that the third parameter is the DSN name
//and not the Database or System name
reportDocument.SetDatabaseLogon("sa", "soft",
"./sqlexpress", "rem", false);

//Load the report by setting the report source
CrystalReportViewer4.ReportSource = reportDocument;



}




Error
Database logon failed.

how to slove this problem?
Posted

You didn't apply right login details. Try to login your database using the same login details(which you have mentioned in your code)

Try again. FYI

Using the SetDatabaseLogon() Method of the ReportDocument Class[^]
 
Share this answer
 
if u r using parameters for ur report, then better to create the parameter in ur .rpt file User Interface and pass the parameter value through code.
It may help you.
C#
ReportDocument doc = new ReportDocument();
doc.Load(@"F:\CallLog\CrCallReportMonthly.rpt");
                doc.SetDataSource(ds);
                doc.VerifyDatabase();
                doc.SetParameterValue("DateFrom", txtDateFrom.Text);
                doc.SetParameterValue("DateTo", txtDateTo.Text);

                CrystalReportViewer1.ReportSource = doc;


here DateFrom and DateTo are Parameters.
 
Share this answer
 
v2
Comments
Member 9960222 12-Sep-13 3:54am    
how to give the procedure name in code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900