I can not open a crystal report with a Microsoft Access database with password

1

I can not open a Crystal Reports report with a password. I get a screen of the report that asks for my password. Attachment captures.

Any solution?


        Dim RptDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument

        RptDocument.Load("c:\Informe.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)

        RptDocument.DataSourceConnections.Clear()

        Dim CTableLogInfo As CrystalDecisions.Shared.TableLogOnInfo
        Dim ConnInfo As CrystalDecisions.Shared.ConnectionInfo = New CrystalDecisions.Shared.ConnectionInfo()

        ConnInfo.Type = CrystalDecisions.Shared.ConnectionInfoType.CRQE
        ConnInfo.ServerName = String.Empty
        ConnInfo.DatabaseName = "c:\dbConPasswrod.mdb"
        ConnInfo.UserID = "Admin"
        ConnInfo.Password = "5354"
        ConnInfo.AllowCustomConnection = False
        ConnInfo.IntegratedSecurity = False

        For Each CTable As CrystalDecisions.CrystalReports.Engine.Table In RptDocument.Database.Tables
            CTable.LogOnInfo.ConnectionInfo = ConnInfo
            CTableLogInfo = CTable.LogOnInfo
            CTableLogInfo.ReportName = "Informe.rpt"
            CTableLogInfo.TableName = CTable.Name
            CTable.ApplyLogOnInfo(CTableLogInfo)
        Next

        CrystalReportViewer1.ReportSource = RptDocument
        CrystalReportViewer1.RefreshReport()


    
asked by Shadros 29.02.2016 в 09:48
source

2 answers

0

After hundreds of tests I have found the solution.

I attach a code for those who need it.

With this code you can assign the location of a database, your password to the desired report.


        Dim cr As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim crCon As New CrystalDecisions.Shared.ConnectionInfo
        Dim crtableLogoninfos As New CrystalDecisions.Shared.TableLogOnInfos
        Dim crtableLogoninfo As New CrystalDecisions.Shared.TableLogOnInfo
        Dim CrTables As CrystalDecisions.CrystalReports.Engine.Tables
        Dim CrTable As CrystalDecisions.CrystalReports.Engine.Table

        cr.Load("c:\Informe.rpt")

        With crCon
            .ServerName = "c:\dbConPasswrod.mdb"
            .UserID = "Admin"
            .Password = Chr(10) & "5354"
        End With

        CrTables = cr.Database.Tables
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crCon
            CrTable.ApplyLogOnInfo(crtableLogoninfo)
        Next

        ' Load Report to cr viewer
        CrystalReportViewer1.ReportSource = cr
        CrystalReportViewer1.Refresh()

    
answered by 02.03.2016 / 11:46
source
0

Try simply using the SetLogon()

RptDocument.DataSourceConnections.Item(0).SetLogon("admin", "xx")

Removes the definition of ConnInfo since it applies to the connection to the database service.

Change Crystal Report Connection at Runtime in Visual studio 2005

On the other hand, you did not evaluate using a data source%%, in this way you would not have a direct connection to the db, but you load a typed Dataset with a code and assign it as Report Source, the connection you control it from code and the abstract report of the db used.

I understand that the example that you put maybe got it from here

How do i change logon info dynamically in crystal report and ms access?

    
answered by 29.02.2016 в 10:10