Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to set Logon Info to a Crystal Report that have 2 different database sources?

Posted on 2008-10-23
3
2,668 Views
Last Modified: 2013-12-25
I have a crystal viewer application in vb 2005 and when a Report has two diferent database sources then the login screen is displayed.

For example if a report has 3 tables from
Server:TestServer
DB: Test1
user: sa
pass: sa

and 2 tables from
Server:TestServer
DB: Test_2
user: sa
pass: sa

how can i set the logon info for each table?

Thanks
Dim intCounter As Integer
        Dim intCounter1 As Integer
 
 
        'object of table Log on info of Crystal report
        Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
 
        'Sub report object of crystal report.
        Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
 
        'Sub report document of crystal report.
        Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim index As Integer
 
        Me.Cursor = Cursors.WaitCursor
 
        Try
            'Load the report
            objReport.Load(sReportName)
 
            'Set the connection information to ConInfo 
            'object so that we can apply the 
            'connection information on each table in the report
            IsLoginSet = False
            strDB = objReport.DataSourceConnections.Item(0).DatabaseName
 
            Select Case UCase(strDB)
                Case "***"
                    ConInfo.ConnectionInfo.UserID = "informes"
                    ConInfo.ConnectionInfo.Password = "****"
                    ConInfo.ConnectionInfo.ServerName = "****"
                    ConInfo.ConnectionInfo.DatabaseName = "****"
                    IsLoginSet = True
                Case "***"
                    ConInfo.ConnectionInfo.UserID = "crystal"
                    ConInfo.ConnectionInfo.Password = "RepCosvi2007"
                    ConInfo.ConnectionInfo.ServerName = "SQLCLUSTER"
                    ConInfo.ConnectionInfo.DatabaseName = "DBCOSVI_PROD"
                    IsLoginSet = True
                Case "FA_***"
                    ConInfo.ConnectionInfo.UserID = "**"
                    ConInfo.ConnectionInfo.Password = "***"
                    ConInfo.ConnectionInfo.ServerName = "***"
                    ConInfo.ConnectionInfo.DatabaseName = "FA_**"
                    IsLoginSet = True
                Case "*****"
                    ConInfo.ConnectionInfo.UserID = "***"
                    ConInfo.ConnectionInfo.Password = "***"
                    ConInfo.ConnectionInfo.ServerName = "***"
                    'ConInfo.ConnectionInfo.DatabaseName = "*****"
                    IsLoginSet = True
                Case "****"
                    ConInfo.ConnectionInfo.UserID = "***"
                    ConInfo.ConnectionInfo.Password = "****"
                    ConInfo.ConnectionInfo.ServerName = "****"
                    ConInfo.ConnectionInfo.DatabaseName = "***"
                Case "****"
                    ConInfo.ConnectionInfo.UserID = "*****"
                    ConInfo.ConnectionInfo.Password = "****"
                    ConInfo.ConnectionInfo.ServerName = "****"
                    ConInfo.ConnectionInfo.DatabaseName = "ED_****"
                Case "****"
                    ConInfo.ConnectionInfo.UserID = "****"
                    ConInfo.ConnectionInfo.Password = "****"
                    ConInfo.ConnectionInfo.ServerName = "****"
                    'ConInfo.ConnectionInfo.DatabaseName = "*****"
                Case "***"
                    ConInfo.ConnectionInfo.UserID = "******"
                    ConInfo.ConnectionInfo.Password = ""
                    ConInfo.ConnectionInfo.ServerName = "***"
                    ConInfo.ConnectionInfo.DatabaseName = "***"
                Case ""
                    Select Case UCase(objReport.DataSourceConnections.Item(0).ServerName)
                        Case "****"
                            ConInfo.ConnectionInfo.UserID = "***"
                            ConInfo.ConnectionInfo.Password = ""
                            ConInfo.ConnectionInfo.DatabaseName = "***"
                        Case "****"
                            ConInfo.ConnectionInfo.UserID = "***"
                            ConInfo.ConnectionInfo.Password = "***"
                            ConInfo.ConnectionInfo.DatabaseName = "FA_***"
                        Case Else
                            If InStr(UCase(objReport.DataSourceConnections.Item(0).ServerName), "RECURSOSHUMANOS1.ACCDB", CompareMethod.Text) > 0 Then
                                ConInfo.ConnectionInfo.UserID = "****"
                                ConInfo.ConnectionInfo.Password = ""
                            End If
                    End Select
 
            End Select
 
 
 
            For intCounter = 0 To objReport.Database.Tables.Count - 1
                objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
            Next
 
            ' Loop through each section on the report then look 
            ' through each object in the section
            ' if the object is a subreport, then apply logon info 
            ' on each table of that sub report
            For index = 0 To objReport.ReportDefinition.Sections.Count - 1
                For intCounter = 0 To _
                    objReport.ReportDefinition.Sections(index).ReportObjects.Count - 1
                    With objReport.ReportDefinition.Sections(index)
                        If .ReportObjects(intCounter).Kind = _
                        CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
                            mySubReportObject = CType(.ReportObjects(intCounter), CrystalDecisions.CrystalReports.Engine.SubreportObject)
                            mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
                            For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count - 1
                                mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo)
                                mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo)
                            Next
                        End If
                    End With
                Next
            Next
 
            'Re setting control 
            CrystalReportViewer.ReportSource = Nothing
 
            objReport.Refresh()
 
            'Set the current report object to report.
            CrystalReportViewer.ReportSource = objReport
 
 
            'Show the report
            CrystalReportViewer.Show()
 
            Me.Cursor = Cursors.Default
            Me.SendByMailToolStripMenuItem.Enabled = True
            Return True
 
        Catch ex As System.Exception
            Me.Cursor = Cursors.Default
            MsgBox(ex.Message)
        End Try

Open in new window

0
Comment
Question by:cosvi-it
  • 2
3 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 100 total points
ID: 22790877
To the best of my knowledge you can't unless you are using a subreport for one of the data sources.

Crystal doesn't "officially" support using 2 datasources in a report except through the use of subreports.

They acknowledge it does work for the report but the products that allow viewing don't support it.

mlmcc
0
 
LVL 7

Assisted Solution

by:natloz
natloz earned 25 total points
ID: 22791340
This is where PUSH reporting comes in handy.
You do not bind anything. Populate your 3 datasets in VB and push them into the report. The report is no way tied to a database (or many).
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 100 total points
ID: 22792087
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ORA-04071: missing BEFORE, AFTER or INSTEAD OF keyword 2 62
Automatic Email Reminder 4 57
Very Large data in MYSQL 7 73
Need help in debugging a UDF results 7 22
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question