Vb.NET 2012 和 Crystal 报告支持包 12 - 始终要求数据库登录
Vb.NET 2012 and Crystal Report support packs 12 - always ask for database login
需要你的帮助..
我正在编写 vb.net 2013 年的代码,Crystal 从这里 http://scn.sap.com/docs/DOC-7824 报告 SP12。
我正在尝试使用记录选择并且它运行良好,但是当我添加一些代码以将参数传递给 Crystal 报告时,它开始让我头晕。这是使用 Crystal
中的参数字段传递参数的代码
Report1.SetParameterValue("Prm_Priority", PassingVar)
这是我的完整代码:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
和程序
Dim A As CrystalDecisions.CrystalReports.Engine.Table
Dim B As CrystalDecisions.Shared.TableLogOnInfo
Report1 = New ReportDocument()
Report1.Load("C:\folders\Report1_.rpt")
For Each A In Report1.Database.Tables
B = A.LogOnInfo
With B.ConnectionInfo
.ServerName = ""
.UserID = "someuserid"
.Password = "somepassword"
.DatabaseName = "someDb"
End With
A.ApplyLogOnInfo(B)
Next A
Report1.SetParameterValue("Prm_Priority", Textbox1.text)
Report1.RecordSelectionFormula = "{DB.Table} =" & Trim(Textbox2.text)>
Me.CrystalReportViewer1.ReportSource = Report1
我看了一些参考,但似乎没有任何意义,密码仍然出现,这是我的参考链接:
Crystal Report always asks for database login
http://www.codeproject.com/Questions/73898/Crystal-report-popping-up-login-credential-always
你们能帮帮我吗,我在这里遗漏了什么..提前谢谢你们..
我知道你链接了另一个问题,但是而不是做你正在做的事情,你有没有试过简单地这样做:
crDocument.SetDatabaseLogon("user", "password", "server", "database")
crptViewer.ReportSource = crDocument
当我在单个报告上有多个数据库连接时,我只使用 For Each Table in Tables
就像你所做的那样。
您可能还需要遍历其他子报告(如果有的话)并做同样的事情(您可能会收到数据库登录提示,因为您没有更改的其他内容导致了它)。这是我使用的一个子过程,它一直对我有用。请注意,我已将其从 class 中提取出来,因此 "Me.ServerName" 来自 属性,您可以像上面那样添加它。
此外,Crystal 通过 .Net 的报告对设置时间非常挑剔。您必须在 table 连接之前设置子报表连接。
''' <summary>
''' Applies the contents of the ConnectionString property to the report (if it's been set).
''' </summary>
''' <remarks></remarks>
Private Sub ApplyNewServer(ByVal report As ReportDocument)
If Me.ServerName = "" Then
Exit Sub
End If
For Each subReport As ReportDocument In report.Subreports
For Each crTable As Table In subReport.Database.Tables
Dim loi As TableLogOnInfo = crTable.LogOnInfo
loi.ConnectionInfo.ServerName = Me.ServerName
If Me.UseTrustedConnection = True Then
loi.ConnectionInfo.IntegratedSecurity = True
Else
loi.ConnectionInfo.UserID = Me.Username
loi.ConnectionInfo.Password = Me.Password
End If
crTable.ApplyLogOnInfo(loi)
Next
Next
'Loop through each table in the report and apply the new login information (in our case, a DSN)
For Each crTable As Table In report.Database.Tables
Dim loi As TableLogOnInfo = crTable.LogOnInfo
loi.ConnectionInfo.ServerName = Me.ServerName
If Me.UseTrustedConnection = True Then
loi.ConnectionInfo.IntegratedSecurity = True
Else
loi.ConnectionInfo.UserID = Me.Username
loi.ConnectionInfo.Password = Me.Password
End If
crTable.ApplyLogOnInfo(loi)
'If your DatabaseName is changing at runtime, specify the table location.
'crTable.Location = ci.DatabaseName & ".dbo." & crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next
End Sub
需要你的帮助.. 我正在编写 vb.net 2013 年的代码,Crystal 从这里 http://scn.sap.com/docs/DOC-7824 报告 SP12。 我正在尝试使用记录选择并且它运行良好,但是当我添加一些代码以将参数传递给 Crystal 报告时,它开始让我头晕。这是使用 Crystal
中的参数字段传递参数的代码Report1.SetParameterValue("Prm_Priority", PassingVar)
这是我的完整代码:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
和程序
Dim A As CrystalDecisions.CrystalReports.Engine.Table Dim B As CrystalDecisions.Shared.TableLogOnInfo Report1 = New ReportDocument() Report1.Load("C:\folders\Report1_.rpt") For Each A In Report1.Database.Tables B = A.LogOnInfo With B.ConnectionInfo .ServerName = "" .UserID = "someuserid" .Password = "somepassword" .DatabaseName = "someDb" End With A.ApplyLogOnInfo(B) Next A Report1.SetParameterValue("Prm_Priority", Textbox1.text) Report1.RecordSelectionFormula = "{DB.Table} =" & Trim(Textbox2.text)> Me.CrystalReportViewer1.ReportSource = Report1
我看了一些参考,但似乎没有任何意义,密码仍然出现,这是我的参考链接:
Crystal Report always asks for database login
http://www.codeproject.com/Questions/73898/Crystal-report-popping-up-login-credential-always
你们能帮帮我吗,我在这里遗漏了什么..提前谢谢你们..
我知道你链接了另一个问题,但是而不是做你正在做的事情,你有没有试过简单地这样做:
crDocument.SetDatabaseLogon("user", "password", "server", "database")
crptViewer.ReportSource = crDocument
当我在单个报告上有多个数据库连接时,我只使用 For Each Table in Tables
就像你所做的那样。
您可能还需要遍历其他子报告(如果有的话)并做同样的事情(您可能会收到数据库登录提示,因为您没有更改的其他内容导致了它)。这是我使用的一个子过程,它一直对我有用。请注意,我已将其从 class 中提取出来,因此 "Me.ServerName" 来自 属性,您可以像上面那样添加它。
此外,Crystal 通过 .Net 的报告对设置时间非常挑剔。您必须在 table 连接之前设置子报表连接。
''' <summary>
''' Applies the contents of the ConnectionString property to the report (if it's been set).
''' </summary>
''' <remarks></remarks>
Private Sub ApplyNewServer(ByVal report As ReportDocument)
If Me.ServerName = "" Then
Exit Sub
End If
For Each subReport As ReportDocument In report.Subreports
For Each crTable As Table In subReport.Database.Tables
Dim loi As TableLogOnInfo = crTable.LogOnInfo
loi.ConnectionInfo.ServerName = Me.ServerName
If Me.UseTrustedConnection = True Then
loi.ConnectionInfo.IntegratedSecurity = True
Else
loi.ConnectionInfo.UserID = Me.Username
loi.ConnectionInfo.Password = Me.Password
End If
crTable.ApplyLogOnInfo(loi)
Next
Next
'Loop through each table in the report and apply the new login information (in our case, a DSN)
For Each crTable As Table In report.Database.Tables
Dim loi As TableLogOnInfo = crTable.LogOnInfo
loi.ConnectionInfo.ServerName = Me.ServerName
If Me.UseTrustedConnection = True Then
loi.ConnectionInfo.IntegratedSecurity = True
Else
loi.ConnectionInfo.UserID = Me.Username
loi.ConnectionInfo.Password = Me.Password
End If
crTable.ApplyLogOnInfo(loi)
'If your DatabaseName is changing at runtime, specify the table location.
'crTable.Location = ci.DatabaseName & ".dbo." & crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next
End Sub