Click here to Skip to main content
15,896,063 members
Articles / Programming Languages / Visual Basic

Changing Crystal Report Database logon information at runtime in VS2005

Rate me:
Please Sign up or sign in to vote.
3.40/5 (2 votes)
25 Mar 2008CPOL 42.5K   483   5   2
Resolving Crystal Report "Table not Found" error message after migrationg the VS2003 Code to VS2005

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Cognizant Technologies Solutions
United States United States
I have been working on the mircosoft technolgies for the past 8 years.
My favorites is on wokring at C++, COM/DCOM/COM+, ATL,MFC,.NET ,SQL server and Crystal Report.

Comments and Discussions

 
AnswerChanging Crystal Report Database logon information at runtime Pin
Shanti Lal Namchuriya8-Dec-14 21:14
Shanti Lal Namchuriya8-Dec-14 21:14 
GeneralWant to change datasource location at runtime in vb.net 2005 crystal reports Pin
dkinjal_2820-Jun-08 0:05
dkinjal_2820-Jun-08 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.