Click here to Skip to main content
Licence CPOL
First Posted 25 Mar 2008
Views 11,985
Downloads 138
Bookmarked 3 times

Changing Crystal Report Database logon information at runtime in VS2005

By | 25 Mar 2008 | Article
(untagged)
Resolving Crtsal 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.

Blocks of code should be set as style "Formatted" like this:

			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)

About the Author

Anurag K. Jaiswal

Software Developer (Senior)
Cognizant Technologies Solutions
United States United States

Member

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.


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralWant to change datasource location at runtime in vb.net 2005 crystal reports Pinmemberdkinjal_280:05 20 Jun '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 25 Mar 2008
Article Copyright 2008 by Anurag K. Jaiswal
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid