为什么会出现“数据库登录失败”的提示? .NET对象用作数据源时,在Crystal Reports中使用? [英] Why do I get "Database logon failed" in Crystal Reports when using .NET object as datasource?

查看:115
本文介绍了为什么会出现“数据库登录失败”的提示? .NET对象用作数据源时,在Crystal Reports中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SetDatasource()方法使用项目中的.NET对象作为数据源创建一个简单的报表。但是,当我运行报表时,出现数据库登录失败错误。该报告根本没有连接到数据库-我在这里错过了什么吗?

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?

非常感谢,
D。

Many thanks, D.

已添加:
我想如果包含Controller动作可能会有所帮助。这是一个快速而肮脏的测试,而不是最终的方法:

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");
}

已修复:
D’哦!我用ReportClass代替ReportDocument。更改了该行,由于Load()不是有效的方法,因此也使用Refresh()。现在它可以正常工作!

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!

推荐答案

通过使用适当的类:ReportDocument而不是ReportClass来解决。

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

这篇关于为什么会出现“数据库登录失败”的提示? .NET对象用作数据源时,在Crystal Reports中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆