Introduction
This Article solve the issue of "table not found" error message while exporting the crystal report to the PDF/DOC format in VS2005 after migrating the old code developed in VS2003.
Background
Previously in VS2003, table.Location would report "DATABASE.dbo.NAME" and it was possible to use this to change the Location, but in vs2005 table.Location only reports back the NAME.
Using the code
Deploye the attached file and then pass the ReportDocument as argument to CReportAuthentication.Impersonate(ReportDocument Object)from the place where you want to launch the report.
Imports System.Configuration
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared
Public Class CReportAuthentication
Public Shared Sub Impersonate(ByVal myRpt As ReportDocument)
' Set the login info dynamically for the report
Dim username As String = ConfigurationManager.AppSettings("ReportUser")
Dim password As String = ConfigurationManager.AppSettings("ReportPassword")
Dim Server As String = ConfigurationManager.AppSettings("Server")
Dim Database As String = ConfigurationManager.AppSettings("Database")
Dim logonInfo As New TableLogOnInfo
Dim table As Table
For Each table In myRpt.Database.Tables
logonInfo = table.LogOnInfo
logonInfo.ConnectionInfo.ServerName = Server
logonInfo.ConnectionInfo.DatabaseName = Database
logonInfo.ConnectionInfo.UserID = username
logonInfo.ConnectionInfo.Password = password
table.ApplyLogOnInfo(logonInfo)
'Previously in VS2003, table.Location would report "DATABASE.dbo.NAME" -
'and it was possible to use this to change the Location, but in vs2005 table.
'Location only reports back the NAME. See below for a fix.
'http://vstoolsforum.com/blogs/crystal_reports/archive/2007/06.aspx
table.Location = Database & ".dbo." & table.Name
Next table
End Sub
End Class