gpt4 book ai didi

asp.net - Crystal Report over ASP.Net 运行时数据源更改

转载 作者:行者123 更新时间:2023-12-02 01:11:09 25 4
gpt4 key购买 nike

有一个脚本可以通过 ASP.Net 运行 Crystal 报表、导出并发送到电子邮件。

如果我使用当前数据库而不应用登录,一切正常,但如果我在运行时更改数据源(相同的数据库结构但不同的服务器),则会出现以下问题。

Crystal 2008 运行时

ERROR:System.Runtime.InteropServices.COMException (0x80042018): The table %1 does not exist in the document. at CrystalDecisions.ReportAppServer.Controllers.DatabaseControllerClass.VerifyTableConnectivity(Object Table) at CrystalDecisions.CrystalReports.Engine.Table.TestConnectivity() at ScriptCodeClass.ApplyLogon(ReportDocument cr, ConnectionInfo ci) at ScriptCodeClass.Logon(ReportDocument cr, String server, String db, String id, String pass) at ScriptCodeClass.FunCreatePDFView(String lsHeader, String lsReportType, String msDatabaseUserId, String msDatabasePassword)

此代码可以更改身份验证,但不能更改数据源/服务器,想知道是否需要引用或导入。

Imports System.Collections
Imports System.Data
Imports T1.Tb.Data
Imports System.IO
Imports System.Net
Imports System.Net.Mail
Imports T1.Tb
Imports T1.TB.Public
Imports CrystalDecisions.CrystalReports.Engine.ReportDocument
Imports CrystalDecisions.ReportSource
Imports System.Configuration
Imports System.Data.SqlClient


Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared


References CrystalDecisions.CrystalReports.Engine
References CrystalDecisions.Shared
References System.Web.Services
References System.Data
References T1.Tb.dll
References T1.TB.Public
References T1.P1.dll
References T1.P1.Public
References T1.Tb.Fun


public shared function Logon(cr as ReportDocument, server as string, db as string, id as string, pass as string) as Boolean
'Use this to change the database logon info for a crystal report
dim ci as ConnectionInfo = new ConnectionInfo()
dim subObj as SubreportObject


ci.ServerName = server
ci.DatabaseName = db
ci.UserID = id
ci.Password = pass


if ApplyLogon(cr, ci) then
for each obj as ReportObject in cr.ReportDefinition.ReportObjects
If (obj.Kind = ReportObjectKind.SubreportObject) Then
// if typeof obj.Kind.GetType() is CrystalDecisions.Shared.ReportObjectKind then
subObj = ctype(obj, SubreportObject)
if not ApplyLogon(cr.OpenSubreport(subObj.SubreportName), ci) then
return(false)
end if
end if
next
Logon = True
end if
end function


private shared function ApplyLogon(cr as ReportDocument, ci as ConnectionInfo ) as Boolean


dim li as TableLogOnInfo
dim success as Boolean


for each tbl as Table in cr.Database.Tables
li = tbl.LogOnInfo
li.ConnectionInfo = ci
tbl.ApplyLogOnInfo(li)
'check if logon was successful
'if TestConnectivity returns false, check logon credentials
if tbl.TestConnectivity() then
'drop fully qualified table location
if tbl.Location.IndexOf(".") > 0 then
tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)
else
tbl.Location = tbl.Location 'THIS IS LINE LEFT OUT IN ALL SAMPLES I SAW
end if
else
success = false
exit for
end if
success = True
next
end function

最佳答案

首先尝试在代码中将查询构建为字符串,然后将其结果传递给 Crystal 报表以获取报表并通过电子邮件发送。

步骤:1) 构建查询字符串。2)执行该字符串并用结果填充数据集中的数据表3)使用该数据集/数据表在 Crystal 报表中生成报表

关于asp.net - Crystal Report over ASP.Net 运行时数据源更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42825030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com