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

后端 未结 12 2220
故里飘歌
故里飘歌 2020-12-29 14:45

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 l

相关标签:
12条回答
  • 2020-12-29 14:53

    I was struggling with this error for a couple of days. I have a .NET webforms project which uses CrystalReportViewer to load a Crystal Report. Instead of the report loading, I kept getting "Database logon failed".

    I opened the RPT file in Crystal Report Designer and went to Database -> Verify Database

    This gave me a more specific error. FINALLY!!!

    I tracked down the XSD file, moved it to the right location and BOOM

    0 讨论(0)
  • 2020-12-29 14:53

    One of the reason of this error is, when u pass null object to a sub report ....SetDataSource(data) , where data is null

    0 讨论(0)
  • 2020-12-29 14:57

    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.

    // Create a new customer orders report.
    CustomerOrdersReport report = new CustomerOrdersReport();
    
    // Get the report data.
    DataTable customersTable = getCustomersData();
    DataTable ordersTable = getOrdersData();
    
    // Set datasources.
    report.Database.Tables["Customers"].SetDataSource(customersTable);
    report.Database.Tables["Orders"].SetDataSource(ordersTable ); // Don't forget this line like I did!!
    
    0 讨论(0)
  • 2020-12-29 15:02

    Mine did it when I was sending in a DataSet instead of a DataTable.

    ReportDocument.SetDataSource(dataset.Tables[0]);

    0 讨论(0)
  • 2020-12-29 15:03

    I had to do write the below line of code to get rid of the "Database login error"

    CrystalDecisions.Shared.TableLogOnInfo li;
    li.ConnectionInfo.IntegratedSecurity = false;
    
    0 讨论(0)
  • 2020-12-29 15:05

    Fixed by using the appropriate class: ReportDocument instead of ReportClass.

    0 讨论(0)
提交回复
热议问题