Skip to Content
avatar image
Former Member

Crystal Reports passing credentials to the report so that it only shows data for the logged in user

I've created a report in Visual Studio that is reading data from a SalesLogix (Infor CRM) database. The report works okay but no matter what I pass it the results show only the data that was saved for the user credentials used when creating the report. When creating the report if I connect to the database using the Admin account I see everything, and if I connect to the database using one of the user accounts I see only their data. That's perfect.

So the idea is that I use the credentials the user logged into the site with, pass that data over to Crystal and then only get data for that user. But for some reason it seems that the information I'm passing to the report for the user credentials is being ignored.

I've tried debugging the VB and I can see the username and password are correct and appear to be passing to Crystal but it simply does not work.

Any ideas would be greatly appreciated.

<body>
    <form id="form1" runat="server">
    <div id="wrapper" style="width: 110%">
        <div id="header">
            <UC:TopNav ID="TopNav" runat="server" />
        </div>
        <div class="hrDiv">
        </div>
        <div id="container">
            <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True"
                Height="815px" ReportSourceID="CrystalReportSource1" Width="1023px" EnableDatabaseLogonPrompt="True"
                EnableParameterPrompt="False" HasToggleGroupTreeButton="False" PrintMode="PDF" />
            <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
                <Report FileName="OrdersBooked.rpt">
                </Report>
            </CR:CrystalReportSource>
        </div>
        <div class="hrDiv">
        </div>
        <UC:Footer ID="Footer" runat="server" />
    </div>
    </form>
</body>


Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Web
Imports System.web.Security


Partial Class Orders_Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        Dim fname As String
        fname = Request.PhysicalApplicationPath & "orders\OrdersBooked.rpt"
        Dim user As MembershipUser = Membership.GetUser()
        Dim un As String = user.UserName
        Dim pw As String = user.GetPassword("Tom")
        Dim sn As String = ConfigurationManager.AppSettings("SLXServerName")
        Dim dn As String = ConfigurationManager.AppSettings("SLXDatabaseName")

        ' Load the report
        Me.CrystalReportSource1.ReportDocument.Load(fname)

        Dim myReport As New ReportDocument
        myReport.Load(fname)

        Dim conninfo As New ConnectionInfo
        With conninfo
            .ServerName = sn
            .DatabaseName = dn
            .UserID = un
            .Password = pw
        End With
        myReport.DataSourceConnections.Clear()
        CrystalReportViewer1.ReportSource = myReport
        CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.Pdf
        SetDBLogonForReport(conninfo, myReport)

    End Sub

    Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)
        Dim myTables As Tables = myReportDocument.Database.Tables
        For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
            Dim MyTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
            MyTableLogonInfo.ConnectionInfo = myConnectionInfo
            myTable.ApplyLogOnInfo(MyTableLogonInfo)
        Next

    End Sub

End Class
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Sep 08, 2017 at 07:53 PM

    When you design the report use Trusted Authentication. Then when logging in don't fill in the user name and PW and it should work.

    In code is using ODBC then set Authentication to True.

    Search for these 3 KBA's

    1985571 - How to use sessions in web applications using the Crystal Reports viewer (the complete code)

    1646498 - When to use the 'Replace Connection' method using the Crystal Reports or InProc RAS SDK for .NET

    1553921 - Is there a utility that would help in writing database logon code?

    Don

    Add comment
    10|10000 characters needed characters exceeded