0
votes

In my mind Crystal Reports should not be trying to connect to a database because I am passing the data to the report. The message returned for the offending error is Database logon failed.

myReport..SetDataSource(ds.Tables(0))

I am receiving the following error in production quite a bit. It does occur every time the report is run but the error occurs frequently.

Message :Database logon failed. Source :Analysis Server Stack Trace : at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)

2
Please check my answer I fixed this issue. stackoverflow.com/questions/54229570/… - Syed

2 Answers

0
votes

I faced exactly the same issue. Was using push method (Though I was passing data to the report instead of runtime DB pull method) to show crystal report but even then Crystal Report was not showing up in the Crystal Report Viewer and this nasty 'Database Logon Failed' error was coming. The report shows up fine in Visual Studio but is empty with this error in the viewer when running the IIS deployed web application.

All the while I thought my application which generates Crystal Report in Crystal Report Web viewer needed the PC Admin user credentials to work when deployed in IIS on our web server. (IIS -> My web application -> Advanced Settings - > Set Physical path credentials...but this is not needed and whenever there was change in user password I had to manually set the password again to make the Crystal report show up in the viewer in my web application - well this was a manual work around I followed until I got the solution !! Read further)

Figured out this Database Logon error was actually because I was just setting the entire dataset to the datasource for the Crystal Report's Main report and forgot to set datasource separately for the sub reports I had in my report. Crystal Report looks for it too :)

So those of you folks who have sub-reports in your crystal report, you should set the datasource separately to all the sub-reports too apart from the Main report. And voila that solved the issue for me !!! And I love crystal reports again :)

This is the wrong way to set data source if there are sub reports too in the crystal report -


Dim myReportDataset as New Dataset 
Dim rptCrystalReport As New MyCrystalReport 
//Fetch data from DB as datatables and set to the dataset
...
//Process your dataset and dataset tables here
....
//Setting Datasource to report 
rptCrystalReport.SetDataSource(myReportDataset)

The correct method is as below :


Dim myReportDataset as New Dataset 
Dim rptCrystalReport As New MyCrystalReport
//Fetch data from DB as datatables and set to the dataset
...
//Process your dataset and dataset tables here
....
//Setting Datasource to report
rptCrystalReport.SetDataSource(myReportDataset)
rptCrystalReport.Subreport.Item("sub_report1").SetDataSource(myReportDataset.Tables("Sub_Report1_Datatable"))
rptCrystalReport.Subreport.Item("sub_report2").SetDataSource(myReportDataset.Tables("Sub_Report2_Datatable"))
0
votes

Step # 1 Right Click in Report Database -> Set Datasource Location > Click Update Button OLE DB Provider -> Select SQL Server Native Client 11.0 -> Enter DB Credential + Database select -> Finished -> Click Update Button again.

Make sure in IIS - Server should have After Successfully Publish folder only deploy into IIS not include any Report Folder.

SQL Server Native Client 11.0 installed Same version of Crystal Report Code:

        ReportDocument rpt = new ReportStatement();
        TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        Tables CrTables;
        rConnectionInfo.ServerName = "10.10.50.243";
        crConnectionInfo.DatabaseName = "StudentDB";
        crConnectionInfo.UserID = "DBAdmin";
        crConnectionInfo.Password = "abc@123";
        CrTables = rpt.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
        {
            crtableLogoninfo = CrTable.LogOnInfo;
            crtableLogoninfo.ConnectionInfo = crConnectionInfo;
            crtableLogoninfo.ConnectionInfo.IntegratedSecurity = false;
            CrTable.ApplyLogOnInfo(crtableLogoninfo);
        }
        rpt.SetDatabaseLogon("DBAdmin", "abc@123", "192.168.10.243", "StudentDB");
        rpt.SetDataSource(ds);
        rpt.Refresh();