简体   繁体   English

Crystal Report登录失败问题

[英]Crystal Report Logon Failed Problem

I am using.... 我在用....

Framework 3.5 C# Visual Studio 2008 and web based application Framework 3.5 C#Visual Studio 2008和基于Web的应用程序

I have created reports using Dataset ie 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. 但有时CR查看器开始弹出错误“Logon Failed”,登录框中填写了登录信息中的数据集名称。

I am searching for its solution for quite some time but did not fine any suitable answer to this. 我正在寻找它的解决方案很长一段时间,但对此没有任何合适的答案。

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. DataSet对象可以包含分层数据。 If your service is returning a DataSet containing hierarchical data, and some of the children are missing, then its schema has effectively changed. 如果您的服务返回包含分层数据的DataSet,并且某些子代丢失,则其架构已有效更改。

There are several ways to ensure that the DataSet has a matching schema. 有几种方法可以确保DataSet具有匹配的架构。 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: 如果要将对象序列化为XML,然后从该XML生成DataSet,那么实现一致架构的一种简单方法是从以下位置更改代码:

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 其中,schemaPath指向通过调用在开发中生成的XSD文件

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. 这也是必须创建报告以使其模式匹配的XML。 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. 如果架构发生更改,则必须在设计器中使用新数据打开报表,并且必须“验证数据库”,然后保存RPT文件。

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

After long efforts i figured the main reason, there was a mistake in my stored procedure which was returning data. 经过长时间的努力,我想到了主要原因,我的存储过程中有一个错误,就是返回数据。

SP returns data from table1 or table2 (they both have same structure), but when I was picking data from table2 i did not write all the column names which were required. SP从table1或table2返回数据(它们都具有相同的结构),但是当我从table2中选择数据时,我没有写出所需的所有列名。

Seems quite weird , i should get something like column not found error instead of database logon failed. 看起来很奇怪,我应该得到类似列未找到错误而不是数据库登录失败。

I was facing the same issue at the time, when I moved the application from the development machine to the real server. 当我将应用程序从开发机器移动到真实服务器时,当时我遇到了同样的问题。 It was an IIS7 MVC application( CR 13.0) with trusted authentication to the SQL server. 它是一个IIS7 MVC应用程序(CR 13.0),具有对SQL Server的可信身份验证。

The way I fixed it, was by creating a new application pool for the application. 我修复它的方法是为应用程序创建一个新的应用程序池。 I give permission for the new application pool user IIS APPPOOL\\applicationpoolname to the SQL server database that was used in the application. 我将新应用程序池用户IIS APPPOOL\\applicationpoolname权限授予应用IIS APPPOOL\\applicationpoolname使用的SQL Server数据库。 Then the error went away. 然后错误就消失了。

My assumption is that, the userlogininfo applied through code is not always used by the CR runtime , instead it uses the IIS user login info. 我的假设是,CR运行时并不总是使用通过代码应用的userlogininfo,而是使用IIS用户登录信息。

Try this out. 试试吧。 Also make sure you have right version of crystal report in all places 还要确保所有地方都有正确版本的水晶报告

private ConnectionInfo crConnectionInfo = new ConnectionInfo();
        ReportDocument rpt = new ReportDocument();
        protected void Page_Load(object sender, EventArgs e)
        {
            CrystalReportViewer1.Width = 900;
            CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
            BindReport();
        }

        private void BindReport()
        {

            rpt.Load(Server.MapPath("ProductList.rpt"));
            DataSet ds = getReportData();
            rpt.SetDataSource(ds.Tables[0]);
            CrystalReportViewer1.ReportSource = rpt;
        }

        private DataSet getReportData()
        {
            DataSet ds = new DataSet();
            string ConnectionString = ConfigurationManager.ConnectionStrings["myconn"].ConnectionString;
            SqlConnection con = new SqlConnection(ConnectionString);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "GetProductList";
            cmd.CommandType = CommandType.StoredProcedure;            
            con.Open();
            cmd.Connection = con;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            sda.Fill(ds, "ctable");
            con.Close();
            return ds;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM