Database Login failed in Crystal Reports

smcdevelopments 1 Reputation point
2021-12-13T04:28:15.747+00:00

In my application, I have created a report in HTML view.

For that, I have used the view model to load the data.

Now to convert it to the pdf and save it to the file I wanted to create a crystal report using the same view model.

So I created a new crystal report.

Then I choose my view data models from the .net project list in the crystal report wizard.

For this, there are two view models I'm using. and then I created the report.

This is the code I run to show the HTML view report.

public ActionResult Index(int id)
{
AppRequest appRequest = db.AppRequest.Find(id);
if (appRequest.General.Count != 0)
{
List<ReportViewModel>RequestView = new List<ReportViewModel>();
var ReqDetails = (from a in db.AppRequest
join e in db.CreateEmployee on a.Req_By equals e.Id
join c in db.CreateCompany on e.CompanyId equals c.Id
join d in db.CreateDesignation on e.DesignId equals d.Id
join dep in db.CreateDepartment on e.DepId equals dep.Id
join g in db.General on a.Id equals g.Req_Id
where a.Id == id
select new ReportViewModel
{
RequestedDate = a.Req_Date.ToString(),
RequestBy = e.EmpName,
CompanyName = c.CompanyName,
RequestByDessignation = d.Designation,
RequestByDepartment = dep.Department,
ApprovalId = g.ApprovedNumber,
CoverNote = a.Req_CoverNote,
GeneralItemsApprovedList = (from a in db.AppRequest
join g in db.General on a.Id equals g.Req_Id
join gi in db.GeneralItms on g.Id equals gi.General_Id
where a.Id == id && gi.IsApproved == true
select new GeneralItemsApprovedList
{
ItemDescription = gi.Attachment_Description,
ItemPrice = gi.Attachment_Amount.ToString(),
GenId = gi.Id
}).ToList(),
ApprovalList = (from a in db.AppRequest
join ap in db.ApprovalProcess on a.Id equals ap.Req_Id
join pa in db.ApproveParties on ap.Id equals pa.ApprovalProcess_Id
join ae in db.CreateEmployee on pa.Approver_Id equals ae.Id
join ad in db.CreateDesignation on ae.DesignId equals ad.Id
where a.Id == id
select new ApprovalList
{
ApproveDate = pa.Approved_Date.ToString(),
ApprovedBy = ae.EmpName,
ApprovedByDessignation = ad.Designation,
}).ToList()
}).ToList();
return View("ApprovedReport", ReqDetails);
}

So same ReqDetails I pass it to the crystal report data source.

CrystalReports.cryGeneralRequest rpt = new CrystalReports.cryGeneralRequest();
rpt.Load(Path.Combine(Server.MapPath("~/CrystalReports"), "cryGeneralRequest.rpt"));
rpt.SetDataSource(ReqDetails);
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
try
{
Stream steam = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
steam.Seek(0, SeekOrigin.Begin);
return File(steam, "application/pdf", "General.pdf");
}
catch (Exception ex)
{
throw;
}

in the Streamline it returns an error "Database logon failed".

This is the first time I'm trying to create a crystal report in asp MVC project. I want to know Is possible to pass data from the view model to the crystal report as I did here? and any solutions will be grateful. Thanks.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,287 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,304 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,071 Reputation points
    2021-12-13T06:30:36.627+00:00

    Hi @smcdevelopments ,

    it returns an error "Database logon failed".

    If you are using ADO.NET DataSets as your datasource, it is possible for the DataSet definition to get out of sync with the definition in the report. Selecting the Database->Verify Database option from the report designer's context menu will often fix this problem.
    Also, you will get this error if your report has linked tables and you fail to set the datasource for one of the tables. The fix is either to remove the table from the report, or set it's datasource correctly.
    For example, if your report has a Customers table and an Orders table linked together on some key you will need to set the datasource for both tables. If you forget and set only one, you will get a "Database logon failure" error which is fairly misleading.

    This is the first time I'm trying to create a crystal report in asp MVC project. I want to know Is possible to pass data from the view model to the crystal report as I did here?

    You could bind your data source without viewmodel and SetDataSource on the crystal report.
    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments