Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get "Database logon failed" in Crystal Reports when using .NET object as datasource?

I am creating a simple report using a .NET object from my project as datasource, using SetDatasource() method. However, when I run the report I get "Database logon failed" error. This report is not connecting to a DB at all - have I missed something here?

Many thanks, D.

ADDED: I guess it will probably help if I include the Controller action. It's a quick and dirty test, not what the final method will look like:

public ActionResult StewardSheets(int showId, int groupId)
{
    ReportClass rptH = new ReportClass();
    rptH.FileName = DataHelper.getReportFilePath("Test.rpt",this);

    NZDSDataContext dataContext = new NZDSDataContext();
    var showDetails = (from s in dataContext.Shows
                       where s.ID == showId
                       select new StewardSheetModel
                       {
                           EventDate = s.EventDate.ToLongDateString(),
                           Region = s.Region.Name,
                           ShowTitle = s.Name
                       }).FirstOrDefault();

    List<StewardSheetModel> details = new List<StewardSheetModel>();
    details.Add(showDetails);

    rptH.SetDataSource(details);

    rptH.Refresh();
    Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    return File(stream, "application/pdf");
}

FIXED: D'oh! I used ReportClass instead of ReportDocument. Changed that line, and also use Refresh() since Load() is not a valid method. Now it works just fine!

like image 564
codedog Avatar asked Nov 30 '10 00:11

codedog


People also ask

Why data is not showing in Crystal Report?

Check the Select Expert in Crystal Report to see if it is excluding the record: Open the report in Crystal Reports and select Report > Select Expert. If any criteria excludes the record, remove that criteria. If unsure, remove all criteria and run the report.


1 Answers

I started getting the notorious "database logon failed" error on a Windows Server 2016 machine after the July 2018 windows server updates. The report ran fine in Visual Studio 2017 on my dev machine, but not in IIS on Windows Server 2016 in production.

After a day of investigation, I installed the Microsoft OLE DB Driver for SQL Server on my development machine - https://docs.microsoft.com/en-us/sql/connect/oledb/oledb-driver-for-sql-server?view=sql-server-2017. I created a report connection in the Crystal report database expert using the MSOLEDBSQL provider. I had to install the Microsoft OLE DB Driver for SQL Server on the production Windows Server 2016 machine as well.

It turns out Microsoft has decided to deprecate the Microsoft OLE DB Provider for SQL Server. This and the native client no longer seem to work with Crystal Reports.

like image 116
Mike Moore Avatar answered Nov 11 '22 05:11

Mike Moore