Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crystal Report Logon Failed Problem

I am using....

Framework 3.5 C# Visual Studio 2008 and web based application

I have created reports using Dataset i.e. my service gives me data set and I bind that dataset with report.

But sometimes CR viewer started popping up error "Logon Failed" with login box with dataset name filled in login information.

I am searching for its solution for quite some time but did not fine any suitable answer to this.

like image 450
Zeeshan Umar Avatar asked May 19 '26 10:05

Zeeshan Umar


2 Answers

Are you passing along your creditials in your code:

ReportDocument rep = new ReportDocument();
rep.FileName = Server.MapPath("CrystalReport1.rpt");
set.SetDatabaseLogon("username", "password", "sql-server", "database"); // this line pass the login parameters required for login
like image 136
Mark Kram Avatar answered May 21 '26 00:05

Mark Kram


This error is unfortunately ambiguous because it is the generated error for dozens of unrelated problems. In this case, the "Logon failed" is likely due to an occasional schema mismatch.

The DataSet object can contain hierarchical data. If your service is returning a DataSet containing hierarchical data, and some of the children are missing, then its schema has effectively changed.

There are several ways to ensure that the DataSet has a matching schema. If you are serializing objects into XML and then generating the DataSet from that XML, then a simple way to achieve a consistent schema is to change your code from:

reportData.ReadXml(new MemoryStream(Encoding.UTF8.GetBytes(reportXml)));

to

reportData.ReadXmlSchema(schemaPath);
reportData.ReadXml(
        new MemoryStream(Encoding.UTF8.GetBytes(reportXml)),
        XmlReadMode.IgnoreSchema
    );

where schemaPath points to an XSD file that was generated earlier in development with a call to

File.WriteAllText(
        @"C:\MyTempPath\MyReportName.xsd", 
        reportData.GetXmlSchema(), 
        Encoding.Unicode
    );

When generating the schema, you will also want that schema to be as complete of a representation of the data as possible, so you will want to use as complete of a hierarchy of data as possible. This is also the XML that the report must be created off of so that its schema matches. If the schema changes, then the report must be opened in the designer with the new data and you must "verify database" and then save the RPT file.

like image 41
DaveMorganTexas Avatar answered May 20 '26 23:05

DaveMorganTexas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!