加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

Crystal报表对ASP.Net运行时数据源的更改

发布时间:2020-12-16 03:50:15 所属栏目:asp.Net 来源:网络整理
导读:有一个脚本通过ASP.Net运行水晶报告,导出并发送到电子邮件. 如果我使用当前数据库而不应用登录一切正常但如果我在运行时更改数据源(相同的数据库结构但不同的服务器),那么下面的问题. Crystal 2008运行时 ERROR:System.Runtime.InteropServices.COMException
有一个脚本通过ASP.Net运行水晶报告,导出并发送到电子邮件.

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

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)使用该数据集/数据表在水晶报告中生成报告

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读