locked
SetDatabaseLogon Array -- Crystal Report RRS feed

  • Question

  • User-1103262355 posted

    Hi All,

    I have on rpt file from my DBA, when i am running this it asking two ODBC connection.

    When i use the below one odbc connected but i still i need to supply u/p for other.

    irpt.SetDatabaseLogon("mysqlu", "mysqlp")
    irpt.SetParameterValue("Cusno", "300039")

    How i can supply the same username and password for other MS SQL ODBC?

    i tried to use something below but it never work.

    irpt.SetDatabaseLogon[0]("mysqlu", "mysqlp")
    irpt.SetParameterValue[0]("Cusno", "300039")

    irpt.SetDatabaseLogon[1]("mssqlu", "mssqlu")
    irpt.SetParameterValue[1]("Cusno", "300039")

    Error:
    Error 1 Overload resolution failed because no accessible 'SetDatabaseLogon' accepts this number of arguments.



    I will appriciate for your suggestions.

    Sunday, January 30, 2011 2:05 AM

All replies

  • User-1103262355 posted

    I did below trick and it is working. But still i am looking some better and profession way to solve this.


    Public CorporateAssessmentReport = New ReportDocument()
    
    Dim reportPath As String = Server.MapPath("CusReports.rpt")
            CorporateAssessmentReport.Load(reportPath)
            CorporateAssessmentReport.SetParameterValue("Custo", "30087")
    
            Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
            myConnectionInfo.ServerName = "MySQL"
            myConnectionInfo.DatabaseName = "Cusinfo"
            myConnectionInfo.UserID = "root"
            myConnectionInfo.Password = "123456"
    
            SetDBLogonForReport(myConnectionInfo, CorporateAssessmentReport, "Cus_tab")
            SetDBLogonForReport(myConnectionInfo, CorporateAssessmentReport, "Cus_Finc")
    
           RVeiwer.ReportSource = CorporateAssessmentReport
    
    
    Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument, ByVal TableName As String)
            Dim myTables As Tables = myReportDocument.Database.Tables
            For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
                Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
    
                If myTable.Name = TableName Then
                    myTableLogonInfo.ConnectionInfo = myConnectionInfo
                    myTable.ApplyLogOnInfo(myTableLogonInfo)
                Else
                    CorporateAssessmentReport.SetDatabaseLogon("MsSQL_Uswer", "MsSQL_PWS")
                End If
            Next
        End Sub



    Sunday, January 30, 2011 3:45 AM
  • User1933630939 posted

    Imports CrystalDecisions.Shared
    Imports CrystalDecisions.CrystalReports.Engine

    Then paste this in your (not Page_Load) Page_Init event handler:

    Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
    Dim myReport As New ReportDocument()
    myReport.Load(Server.MapPath("ReportName")) ' name of the crystal report
     
    Dim myTables As Tables = myReport.Database.Tables
     
    For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
    Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
    myConnectionInfo.ServerName = "" ' <SQL servername>
    myConnectionInfo.DatabaseName = "" ' leave database name blank
    myConnectionInfo.UserID = "" ' username
    myConnectionInfo.Password = "" ' password
    myTableLogonInfo.ConnectionInfo = myConnectionInfo
    myTable.ApplyLogOnInfo(myTableLogonInfo)
    Next
     
    CrystalReportViewer1.ReportSource = myReport

    Thursday, August 11, 2011 7:55 AM