CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2010
    Posts
    4

    Database Login Crystal Reports

    Hi all !

    When I'm calling my report, the Database Login prompt comes up (see picture). I know that you have to use the setDatabaseLogon method from the Reportdocument, but if I use it, only the username and the password will be filled in and I can't set the database name because that field is disabled..

    How can I fix this ?
    Last edited by KevinVGW; August 4th, 2022 at 06:55 AM.

  2. #2
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Database Login Crystal Reports

    Give us more details, please
    Windows version
    Crystal Reports version
    Application language & version
    etc.
    And post the relevant code where you call the rpt

    JG

  3. #3
    Join Date
    Sep 2010
    Posts
    4

    Re: Database Login Crystal Reports

    Hi, thanks for your reaction..

    I've made my Visual Basic.NET application in Visual Studio 2008 on a Windows 7 operating system.
    The computers on which I want to run my application are using Windows XP. In Visual Studio 2008 I'm using Crystal Reports (10?? I'm not sure about that number, but it was installed with my Visual Studio) and in the report I'm making connection to a SQL Server 2005 that runs on my Microsoft Small Business Server 2008.

    Here you have the code to open my report:


    Dim cryRpt As New ReportDocument
    cryRpt.Load("Kasticket.rpt")
    cryRpt.SetDatabaseLogon("user", "password", "databasename", "database")

    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldDefinition As ParameterFieldDefinition
    Dim crParameterValues As New ParameterValues
    Dim crParameterDiscreteValue As New ParameterDiscreteValue
    Dim crParameterRangeValue As New ParameterRangeValue

    For i As Integer = 0 To crParameterDiscreteValueList.Count - 1
    crParameterDiscreteValue.Value = crParameterDiscreteValueList.Item(i)
    crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields()
    crParameterFieldDefinition = crParameterFieldDefinitions.Item(crParameterFieldDefinitionList.Item(i))
    crParameterValues = crParameterFieldDefinition.CurrentValues
    crParameterValues.Add(crParameterDiscreteValue)
    crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    Next

    CrystalReportViewer1.ReportSource = cryRpt
    CrystalReportViewer1.Refresh()

  4. #4
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Database Login Crystal Reports

    Try next code :

    Code:
    Public cryRpt  As CrystalDecisions.CrystalReports.Engine.ReportDocument
    Public CRTable As CrystalDecisions.CrystalReports.Engine.Table
    Public CRTLI   As CrystalDecisions.Shared.TableLogOnInfo
    
        cryRpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
        cryRpt.Load(Kasticket.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
        For Each CRTable In cryRpt.Database.Tables
            CRTLI = CRTable.LogOnInfo
            With CRTLI.ConnectionInfo
                .ServerName = "MyServerName"
                .UserID = "MyUserID"
                .Password = "MyPassword"
                .DatabaseName = "MyDBname"
            End With
            CRTable.ApplyLogOnInfo(CRTLI)
        Next CRTable
        '
        'Your Parameters' code goes here
        '
        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()
    JG

  5. #5
    Join Date
    Sep 2010
    Posts
    4

    Re: Database Login Crystal Reports

    Hi Jggtz,

    I have tried your code on my computer and it works fine. But I have the same problem when I tried it on another computer.. Everything is correctly filled in, except the Database name

  6. #6
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Database Login Crystal Reports

    The executable file does works ok in your pc, but it doesn't in another pc?
    Or are you running it in vb6 ide ?
    Did you install your project in that pc?
    Also, say the data source you use in CR to get access to server & db & tables

    JG

  7. #7
    Join Date
    Sep 2010
    Posts
    4

    Re: Database Login Crystal Reports

    Done ! I can open my reports successfull on my other PC's.. I think that I made a wrong connection to my database.. I used SQL Native Client, but now I'm using Microsoft OLE DB Provider for SQL Server. Now I can edit my reports and my program can work.. Thanks for your help, this thread can be closed..

  8. #8
    Join Date
    Mar 2014
    Posts
    1

    Re: Database Login Crystal Reports

    crConnectionInfo.ServerName = "YOUR SERVER NAME";
    crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
    crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
    crConnectionInfo.Password = "YOUR DATABASE PASSWORD";

    CrTables = cryRpt.Database.Tables ;
    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
    {
    crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
    }

    full source.. Crystal Reports logon parameters

    John

  9. #9
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Database Login Crystal Reports

    If you study the code, it's exactly the same (coded in different way) but yours is 4 years later
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured