问题描述
我正在使用 Crystal Reports 和 MS SQL Server.我需要重新映射水晶报表以指向同一 SQL Server 上的不同数据库.是否有自动执行此操作的方法,还是我必须为每个报告重新映射?我目前正在通过添加一个新的数据连接来执行此操作,然后使用指定的参数更新存储过程以更改数据库(目录).此外,在重新映射后,显示报告的 .asp 崩溃如下:
I am working with Crystal Reports and MS SQL Server. I need to remap the crystal report to point to a different database on the same SQL Server. Is there an automated way of doing this, or do I have to remap for every single report? I am currently doing this by adding a new data connection, and then updating the stored procedure with the specified paramether to change database(catalog). Also, after remaping, the .asp that displays the report crashes like this:
活动服务器页面,ASP 0115 (0x80004005)外部对象中出现可捕获错误 (E06D7363).脚本无法继续运行.
Active Server Pages, ASP 0115 (0x80004005) A trappable error (E06D7363) occurred in an external object. The script cannot continue running.
代码是:
设置 mainReportTableCollection = Session("oRpt").Database.Tables
Set 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
但是,如果我注释掉最后两个分配,它就会运行.
It runs, however, if i comment out the last two assignations.
提前致谢.
真的是你的,西尔维.
推荐答案
以后你会发现我使用的过程(我动态地简化了它,抑制了我们自己的对象和全局变量).此过程允许将报表从开发时使用的原始连接重定向到活动 SQL 服务器.它是用 VB 编写的,主要使用 2 个对象:
You'll find hereafter the procedure I use (I simplified it on the fly, suppressing our own objects and global variables). This procedure allows to redirect a report from an original connection used at development time to the active SQL server. It is written in VB and uses 2 main objects:
- 通过水晶报表实例打开的原始报表对象
- ADODB 连接是当前 SQL 服务器的活动连接(称为 P_currentConnection)
在应用程序中查看/打印报表对象之前调用此函数(也可以是子函数).它可用于在复制数据库之间分发报告时,用户根据他们的位置连接到不同的服务器/数据库.
This function (could be also a sub) is called before viewing/printing the report object in the application. It can be used when distributing reports among replicated databases where users, depending on their location, connect to different servers/databases.
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
可以通过如下过程调用:
It can be called with a procedure such as:
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)
如果您的报告包含子报告,您可能还必须将它们重定向到活动连接.在这种情况下,您必须浏览报表中的所有对象,检查属于报表类型的对象并将它们重定向到新连接.我相信你会很高兴在这个原始过程中添加相应的额外行.
In case your report includes subreports, You might also have to redirect them to the active connection. In this case, you'll have to browse all objects in your report, check the ones that are of the report type and redirect them to the new connection. I am sure you'll have fun adding the corresponding extra lines to this original procedure.
这篇关于Crystal Report 数据源重映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!