【问题标题】:Crystal Report Datasource remapCrystal Report 数据源重映射
【发布时间】:2015-02-05 07:58:12
【问题描述】:

我正在使用 Crystal Reports 和 MS SQL Server。 我需要重新映射水晶报表以指向同一 SQL Server 上的不同数据库。是否有自动执行此操作的方法,还是我必须为每个报告重新映射?我目前正在通过添加一个新的数据连接来执行此操作,然后使用指定的参数更新存储过程以更改数据库(目录)。此外,重新映射后,显示报告的 .asp 崩溃如下:

活动服务器页面,ASP 0115 (0x80004005) 外部对象中出现可捕获错误 (E06D7363)。脚本无法继续运行。

代码是:

设置 mainReportTableCollection = Session("oRpt").Database.Tables

For Each mnTable in mainReportTableCollection
  With mnTable.ConnectionProperties
   .Item("user ID") = "<some_login_name>"
   .Item("Password") = "<some_password>"
   .Item("DSN") = "<some_DSN>"
   .Item("Database") ="<some_Database>"
  End With
Next

但是,如果我注释掉最后两个分配,它就会运行。

提前致谢。

真的是你的,西尔维。

【问题讨论】:

  • 您使用的是哪个版本的 Crystal Reports?另外,你手头有什么工具? ASP 并不理想,除非您需要在 Web 应用程序中动态执行。

标签: sql-server asp-classic crystal-reports


【解决方案1】:

您将在下文中找到我使用的过程(我在运行过程中对其进行了简化,抑制了我们自己的对象和全局变量)。此过程允许将报表从开发时使用的原始连接重定向到活动 SQL 服务器。它是用 VB 编写的,主要使用 2 个对象:

  1. 通过水晶报表实例打开的原始报表对象
  2. ADODB 连接是当前 SQL 服务器的活动连接(称为 P_currentConnection)

在应用程序中查看/打印报表对象之前调用此函数(也可以是子函数)。它可以用于在复制数据库之间分发报告,其中用户根据他们的位置连接到不同的服务器/数据库。

Public Function connectReportToDatabase( _
    P_report As CRAXDRT.Report)

Dim table As CRAXDRT.DatabaseTable, _

For Each table In P_report.Database.tables

    If table.DllName <> "crdb_ado.dll" Then
        table.DllName = "crdb_ado.dll"
    End If

    table.ConnectionProperties.DeleteAll

    table.ConnectionProperties.Add "Provider", P_currentConnection.Provider
    table.ConnectionProperties.Add "Data source", P_currentConnection.Properties("Data source").Value
    table.ConnectionProperties.Add "Database", P_currentConnection.DefaultDatabase
    table.ConnectionProperties.Add "Integrated security",  P_currentConnection.Properties("Integrated security").Value
    table.ConnectionProperties.Add "Persist Security Info", P_currentConnection.Properties("Persist Security Info").Value
    table.ConnectionProperties.Add "Initial Catalog", P_currentConnection.Properties("Initial Catalog").Value

    table.SetTableLocation table.location, "", P_currentConnection.ConnectionString

    table.TestConnectivity

Next table

可以通过如下过程调用:

Dim crystal As CRAXDRT.Application, _
    m_report as CRAXDRT.report        

Set crystal = New CRAXDRT.Application
Set m_rapport = crystal.OpenReport(nameOfTheReport & ".rpt")

connectreportToDatabase(m_report)

如果您的报告包含子报告,您可能还必须将它们重定向到活动连接。在这种情况下,您必须浏览报表中的所有对象,检查属于报表类型的对象并将它们重定向到新连接。我相信你会很高兴在这个原始过程中添加相应的额外行。

【讨论】:

    【解决方案2】:

    您可以从当前报告连接信息中获取任何信息。因此,如果您不更改服务器,请将 CrystalServer 变量设置为报告当前服务器。

    'SET REPORT CONNECTION INFO
    For i = 0 To rsource.ReportDocument.DataSourceConnections.Count - 1
        rsource.ReportDocument.DataSourceConnections(i).SetConnection(crystalServer, crystalDB, crystalUser, crystalPassword)
    Next
    
    For i = 0 To rsource.ReportDocument.Subreports.Count - 1
        For x = 0 To rsource.ReportDocument.Subreports(i).DataSourceConnections.Count - 1
            rsource.ReportDocument.OpenSubreport(rsource.ReportDocument.Subreports(i).Name).DataSourceConnections(x).SetConnection(crystalServer, crystalDB, crystalUser, crystalPassword)
        Next
    Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多