导航到Crystal Reports VS2008上的下一页时,登录失败 [英] Logon failed error when navigating to next page on Crystal Reports VS2008

查看:216
本文介绍了导航到Crystal Reports VS2008上的下一页时,登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2008中开发了一个Crystal报表,它使用了几个不同的数据库作为DataSource。一切工作正常,直到我尝试导航到第2页。有效的代码(因为它的结果有限)看起来像这样

I'm developing a crystal report in Visual Studio 2008 that uses a couple of different databases as DataSource. Everything was working fine until I try to navigate to page 2. The code that works (because it has limited results) looks like this

Dim mssqlstr As String
mssqlstr = "SELECT TOP 1 t1.*, t2.column1, t2.column2 FROM 
        tablename1 As t1, tablename2 As t2 WHERE t1.ID = '" & txtID.Text & "'
        AND t2.column2 = RTRIM(LEFT(t1.column_2, 2)) ORDER BY t1.ID DESC"
Dim DAms As New OleDbDataAdapter(mssqlstr, conn)
DAms.Fill(dsQRpt, "tablename")

'The code below is shared by the other subreport functions
QPrpt.Load(Server.MapPath("crreport.rpt"))
QPrpt.SetDataSource(dsQRpt)
crQtrProgress.ReportSource = QPrpt
crQtrProgress.RefreshReport()

但是当我需要一个更大的结果集从这个查询

But when I need a larger result set from this query

mssqlstr = "SELECT column1, column2 FROM tablename ORDER BY ID DESC"

我收到错误


登录失败。

详细信息:crdb_adoplus:对象引用未设置为对象的实例。

文件C中的错误:\Users\ALFRED〜 1.CAL\AppData\Local\Temp\rptQuarterlyProgress {10667888-35C5-41CA-93EF-214A64741965} .rpt:无法连接:参数登录不正确。

Logon failed.
Details: crdb_adoplus : Object reference not set to an instance of an object.
Error in File C:\Users\ALFRED~1.CAL\AppData\Local\Temp\rptQuarterlyProgress {10667888-35C5-41CA-93EF-214A64741965}.rpt: Unable to connect: incorrect log on parameters."

两个查询使用相同的连接字符串,报表字段来自数据表(.xsd)中的拖放字段

Both queries use the same connection string and the report fields are coming from drag and dropped fields in a datasheet (.xsd)

我还应该提到报表使用多个子报表,每个子报表来自不同的DataSource。所有子报告都被类似地编码,除了当结果必须传递到下一页时,它们工作正常。如果我限制结果的数量,然后我从每个子报告,但如果数据转移到另一个页面,所需的结果... kaboom!我收到无法连接...错误。

I should also mention that the report is using multiple subreports with each subreport coming from a different DataSource. All the subreports are coded similarly and work fine except for when the results have to carry over to the next page. If I limit the number of results then the I get the desired results from each subreport but if the data carries over to another page...kaboom! I get the "Unable to connect..." error.

此外,DataSet连接到数据库并显示表数据没有问题。

Also the DataSet connects to the database and displays the table data with no problem. I've been looking for a solution but not finding anything that matches my situation.

感谢您提供任何帮助

解决方案
信用卡会送至 haraman ,以提供答案。这是工作代码

SOLUTION Credit goes to haraman for providing the answer. Here's the working code

    Dim dsQRpt = New Data.DataSet
    Dim QPrpt = New ReportDocument

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        

        If Page.IsPostBack Then
            If Session.Item("CRpt") IsNot Nothing Then
                QPrpt = Session.Item("CRpt")
            End If
            crQtrProgress.ReportSource = QPrpt
            crQtrProgress.RefreshReport()
        Else
            If Session.Item("CRpt") IsNot Nothing Then
               Session.Remove("CRpt")
            End If
            Session.Add("CRpt", QPrpt)
        End If

    End Sub

Protected Sub btRunReport_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim mssqlstr As String    
        mssqlstr = "SELECT column1, column2 FROM tablename ORDER BY ID DESC"

        Dim DAms As New OleDbDataAdapter(mssqlstr, conn)    
        DAms.Fill(dsQRpt, "tablename")

        'Populate Report 
        QPrpt.Load(Server.MapPath("crreport.rpt"))            
        QPrpt.SetDataSource(dsQRpt)
        crQtrProgress.ReportSource = QPrpt

        Session.Add("CRpt", QPrpt) 

End Sub


推荐答案

看起来CrystalReportViewer丢失了PostBack上的ReportDocument。您可以尝试将ReportDocument保存在会话中,然后在PostBack上将其重新分配给CrystalReportViewer上的PageLoad事件,例如

It seems CrystalReportViewer loses the ReportDocument on PostBack. You can try saving the ReportDocument in a session and then on PostBack reassign it to the CrystalReportViewer on PageLoad event such as

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)  Handles Me.Load

    QPrpt.Load(Server.MapPath("crreport.rpt"))
    QPrpt.SetDataSource(dsQRpt)

    If Page.IsPostBack Then
        If Session.Item("CRpt") IsNot Nothing Then
            QPrpt = Session.Item("CRpt")
        End If
    Else
        If Session.Item("CRpt") IsNot Nothing Then
            Session.Remove("CRpt")
        End If
        Session.Add("CRpt", QPrpt)
    End If
    crQtrProgress.ReportSource = QPrpt
    crQtrProgress.RefreshReport()
End Sub

Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
    If Session.Item("CRpt") IsNot Nothing Then
        Session.Remove("CRpt")
    End If
    Session.Add("CRpt", QPrpt)
End Sub

设置LogOnInfo,那么您还可以检查此SO post 在设置DataTable作为DataSource时报告数据库登录

In case you have specific problem in setting LogOnInfo then you may also check this SO post Report asking for database login on setting DataTable as DataSource

这篇关于导航到Crystal Reports VS2008上的下一页时,登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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