在 Crystal Reports VS2008 上导航到下一页时出现登录失败错误 [英] Logon failed error when navigating to next page on Crystal Reports VS2008
问题描述
我正在 Visual Studio 2008 中开发一个水晶报表,它使用几个不同的数据库作为数据源.一切正常,直到我尝试导航到第 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:UsersALFRED~1.CALAppDataLocalTemp
ptQuarterlyProgress {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:UsersALFRED~1.CALAppDataLocalTemp ptQuarterlyProgress {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)
我还应该提到该报表使用多个子报表,每个子报表来自不同的数据源.所有子报表的编码都类似,并且工作正常,除非结果必须延续到下一页.如果我限制结果的数量,那么我会从每个子报表中获得所需的结果,但如果数据转移到另一个页面......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 上将其重新分配给 PageLoad 事件上的 CrystalReportViewer,例如
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 帖子 报告在将 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屋!