I am using Crystal report that comes with visual studio 2008, mvc 2.
i want when user clicks on the link the PDF report is generated.
this is my method to configure crystal report
public ReportClass ConfigureReportClass(string strReportPath, object[] objParameters)
{
ReportClass rptH = new ReportClass();
try
{
rptH = new ReportClass();
rptH.FileName = strReportPath;
int Count = 0;
rptH.Load();
if (objParameters == null)
return rptH;
foreach (object obj in objParameters)
{
ParameterField param = rptH.ParameterFields[Count++]; // first param
param.AllowCustomValues = true;
ParameterDiscreteValue Disparam = new ParameterDiscreteValue();
Disparam.Value = obj;
param.CurrentValues.Add(Disparam);
}
}
catch (Exception ex)
{
throw ex;
}
return rptH;
}
and this one to convert it in to PDF
public System.IO.Stream GetPDFStream(CrystalDecisions.CrystalReports.Engine.ReportClass rptClass)
{
System.IO.Stream stream = rptClass.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return stream;
}
and this one is my action method in controller
public FileResult GetComplaintFile(String ComplaintNumber)
{
HomeBLLC objHomeBLLC = new HomeBLLC();
ReportClass rptH = objHomeBLLC .ConfigureReportClass(Server.MapPath("~/Views/Complaint/ComplaintReport.rpt"), new object[] { ComplaintNumber });
return File( objHomeBLLC.GetPDFStream(rptH),"application/pdf" );
}
i can see preview of my report in design view in visual studio but get the exception at runtime
Logon failed.
Details: 28000:[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user ‘user’.
Error in File C:\Windows\TEMP\ComplaintReport {5BDD522D-04DA-48CD-9F43-A9C648F195D9}.rpt:
Unable to connect: incorrect log on parameters. at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportFormatType formatType)
at myapp.BLL.Home.HomeBLLC.GetPDFStream(ReportClass rptClass) in F:\myapp\BLL\Home\HomeBLLC.CS:line 1082
at myapp.Controllers.ComplaintController.GetComplaintFile(String ComplaintNumber) in F:\myapp\Controllers\ComplaintController.cs:line 709
at myapp.Controllers.ComplaintController.Complaint() in F:\myapp\Controllers\ComplaintController.cs:line 76
at lambda_method(ExecutionScope , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters)2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
at System.Web.Mvc.ControllerActionInvoker.<>c_DisplayClassd.b_a()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation)1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
my DSN is correctly configured because other application which is using same DSN is running the Crystal report correctly.
thanks in advance
i missed the basic thing, after studying the related questions i came to know that i forgot to give the authentication in my configure crystal report method which is necessary
my modified Method is as follows
the Only thing i added is rptH.SetDatabaseLogon(“myusername”, “mypassword”);
to my code and its working.
no idea why i have to give the authentication again because i already gave authentication in my DSN. any Suggestions are Welcome.