Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

sql server - Crystal Report Datasource remap

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:

Active Server Pages, ASP 0115 (0x80004005) A trappable error (E06D7363) occurred in an external object. The script cannot continue running.

The code is:

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.

Thanks in advance.

Yours trully, Silviu.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. The original report object opened through an instance of crystal report
  2. An ADODB connection being the active connection (called P_currentConnection) to the current SQL server

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...