Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have an old application I'm converting from VB6 & Oracle to asp.net with VB and SQL Server. I'm utilizing the old Crystal Reports for conversion time sake. I have the reports working within VS2010 with the exception of the database logon. I've been trying to prevent the db logon via the code behind. The Crystal report uses an ODBC on my development machine to get to the database.

I pasted the code behind for your reference. Stepping through the code I make it all the way through the CrystalReportViewer1.ReportScource where it renders the report. It acts like it sees the ODBC. You can see by the comments I put on each "setDatabaseLogon" line what happens when I have the different values. I either get "load report failed" when all the logon parameters are correct or I get the logon prompt when any one of them is incorrect. If I enter the password at the logon prompt, it renders the report.

I've tried many different ways to get the auto logon to work based on web searches with no luck so far. Any help would be appreciated. ~~ Thanks! Patty

VB
Imports System.Data.Odbc
Imports System.Data.SqlClient
Imports CrystalDecisions
Imports CrystalDecisions.CrystalReports
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Shared.ParameterField
Imports CrystalDecisions.Shared.ParameterFields
Public Class FundsXfer1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack Then
            CrystalReportViewer1.Visible = True
        Else
            CrystalReportViewer1.Visible = False
        End If
    End Sub

    Protected Sub btnRpt_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRpt.Click

        Dim report As TransferHistoryReport = New TransferHistoryReport
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crConnectionInfo As New ConnectionInfo
        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtablelogoninfo As New TableLogOnInfo
        Dim crTables As Tables
        Dim crTable As Table

        Dim user As String = "gratis_admin"
        Dim pswd As String = "admin$1"


        Dim crReportDocument As New ReportDocument()
        crReportDocument.Load("c:\myReports\TransferHistoryReport.rpt")

        Dim paramfields As New ParameterFields
        Dim pfFromDate As New ParameterField()
        Dim pfToDate As New ParameterField()
        Dim pfRac As New ParameterField()
        Dim pfLocId As New ParameterField()
        Dim dcFromDate As New ParameterDiscreteValue()
        Dim dcToDate As New ParameterDiscreteValue()
        Dim dcRac As New ParameterDiscreteValue()
        Dim dcLocId As New ParameterDiscreteValue()

        pfRac.ParameterFieldName = "racfid"
        dcRac.Value = txtRacfid.Text
        pfRac.CurrentValues.Add(dcRac)
        paramfields.Add(pfRac)

        pfLocId.ParameterFieldName = "locid"
        dcLocId.Value = txtLocID.Text
        pfLocId.CurrentValues.Add(dcLocId)
        paramfields.Add(pfLocId)

        pfFromDate.ParameterFieldName = "reportfrom_date"
        dcFromDate.Value = txtFromDate.Text
        pfFromDate.CurrentValues.Add(dcFromDate)
        paramfields.Add(pfFromDate)

        pfToDate.ParameterFieldName = "reportto_date"
        dcToDate.Value = txtToDate.Text
        pfToDate.CurrentValues.Add(dcToDate)
        paramfields.Add(pfToDate)

        CrystalReportViewer1.ParameterFieldInfo = paramfields


        crConnectionInfo.IntegratedSecurity = True
        ' crReportDocument.SetDatabaseLogon(user id, password, ODBC name, database name) 
        ' crReportDocument.SetDatabaseLogon(user, pswd, "GratisSql", "Gratis") 'everything correct; Load Report failed
        crReportDocument.SetDatabaseLogon(user, pswd, "JACDBATEST02", "Gratis") 'doesn't recognize server name
        'crReportDocument.SetDatabaseLogon(user, pswd, "testing", "Gratis") ' any one parm incorrect -- login prompt
        CrystalReportViewer1.ReportSource = crReportDocument

    End Sub
End Class
Posted
Updated 23-Sep-15 5:37am
v2
Comments
Kschuler 23-Sep-15 11:36am    
"Load report failed" can mean a lot of different things. It might not be the login authorities that is the problem. Can you get it to work when you're not by passing the login prompt?
Member 11177651 23-Sep-15 12:00pm    
Yes, it does work when I don't pass the login info. I just have to enter the password. I think it gets the remainder of the login info from the ODBC which is why I only have to enter the password.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900