Vb.NET 2012和Crystal Report支持包12 - 始终要求数据库登录

时间:2015-01-05 15:02:08

标签: vb.net crystal-reports

需要你对这一个的帮助.. 我正在编写来自vb.net 2013和Crystal Report SP12的代码http://scn.sap.com/docs/DOC-7824。 我正在尝试使用记录选择并且运行良好,但是当我添加一些代码将参数传递给Crystal Report时,它开始让我头晕目眩。以下是使用Crystal

中的参数字段传递参数的代码
  

Report1.SetParameterValue(“Prm_Priority”,PassingVar)

以下是我的完整代码:

  

导入CrystalDecisions.CrystalReports.Engine
  导入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
你们能帮助我吗?我在这里错过了一些东西......先谢谢你们......

2 个答案:

答案 0 :(得分:0)

我知道你把另一个问题联系起来,但代替做你正在做的事情,你试过这么简单吗?

crDocument.SetDatabaseLogon("user", "password", "server", "database")
crptViewer.ReportSource = crDocument

当我在一个报表上有多个数据库连接时,我只会像你一样使用For Each Table in Tables

答案 1 :(得分:0)

如果您拥有它们并且执行相同的操作,您可能还需要循环浏览其他子报告(您可能会获得数据库登录提示,因为您不会更改的其他子报告导致它)。这是我使用的子程序,它总是为我工作。请注意,我已将它从课程中删除,因此" Me.ServerName"是来自一个属性,你可以像上面那样添加它。

此外,通过.Net的Crystal Reports在设置时非常挑剔。您必须在表连接之前设置子报表连接。

    ''' <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

http://www.blakepell.com/2010-09-17-crystal-reports-changing-the-database-connection-from-net-subreport-links-and-the-case-of-the-missing-parameter-values