0

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

Active Server Pages,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

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

提前致谢。

真的是你的,西尔维。

4

2 回答 2

3

以后你会发现我使用的过程(我简化了它,抑制了我们自己的对象和全局变量)。此过程允许将报表从开发时使用的原始连接重定向到活动 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)

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

于 2008-10-20T08:10:27.240 回答
0

You can get any of the info from the current report connection info. So if your not changing servers, then set the crystalServer variable to the reports current server.

'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
于 2008-10-16T15:23:48.490 回答