Results 1 to 7 of 7

Thread: [RESOLVED] database login

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    Resolved [RESOLVED] database login

    i have created an application and crystal report using Visual Studio 2005
    , the application able to show and print the report in my pc, and working fine.

    I also created the setup.exe to deploy the crystal report into other
    computer, but when i click the button to generate report,
    the Crystal Report Viewer show a Database Login screen everytime.

    Please help me out. Thanks.


    here is my code.

    Code:
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Web
    Imports System.IO
    Imports CrystalDecisions.Shared
    
    Public Class frmGLTransaction_listing
    
        Private con As New Clsappconfiguration
        Private rptsummary As New ReportDocument
    
        Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
            'rptsummary.Refresh()
            rptsummary.Load(Application.StartupPath & "\Accounting Reports\gl_transaactionlisting.rpt")
            Logon(rptsummary, con.Server, con.Database, con.Username, "sa")
            rptsummary.Refresh()
            rptsummary.SetParameterValue("@frmMth", cboMth1.SelectedItem)
            rptsummary.SetParameterValue("@toMth", cboMth2.SelectedItem)
            rptsummary.SetParameterValue("@year", cboYear.SelectedItem)
            rptsummary.SetParameterValue("@sortedby", cboSorted.SelectedItem)
            rptsummary.SetParameterValue("@frmAcnt", cboAcnt1.SelectedItem)
            rptsummary.SetParameterValue("@toAcnt", cboAcnt2.SelectedItem)
            rptsummary.SetParameterValue("@fxKeyCompany", gCompanyID())
    
            Me.crvRpt.Visible = True
            Me.crvRpt.ReportSource = rptsummary
        End Sub
    
        Function Logon(ByVal cr As ReportDocument, ByVal server As String, ByVal db As String, ByVal id As String, ByVal pass As String) As Boolean
            Dim ci As New ConnectionInfo
            Dim subObj As SubreportObject
            ci.ServerName = server
            ci.DatabaseName = db
            ci.UserID = id
            ci.Password = pass
            If Not (ApplyLogon(cr, ci)) Then
                Return False
            End If
            Dim obj As ReportObject
            For Each obj In cr.ReportDefinition.ReportObjects()
                If (obj.Kind = ReportObjectKind.SubreportObject) Then
                    subObj = CType(obj, SubreportObject)
                    If Not (ApplyLogon(cr.OpenSubreport(subObj.SubreportName), ci)) Then
                        Return False
                    End If
                End If
            Next
            cr.Refresh()
            Return True
        End Function
    
        Function ApplyLogon(ByVal cr As ReportDocument, ByVal ci As ConnectionInfo) As Boolean
            Dim li As TableLogOnInfo
            Dim tbl As Table
            For Each tbl In cr.Database.Tables
                li = tbl.LogOnInfo
                li.ConnectionInfo = ci
                tbl.ApplyLogOnInfo(li)
                If (tbl.TestConnectivity()) Then
                    If (tbl.Location.IndexOf(".") > 0) Then
                        tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)
                    Else
                        tbl.Location = tbl.Location
                    End If
                Else
                    Return False
                End If
            Next
            Return True
        End Function
    
    End Class

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    Re: database login

    i even tried to hardcode this part

    Code:
    Logon(rptsummary, con.Server, con.Database, con.Username, "sa")
    and change it to

    Code:
    Logon(rptsummary, "myServer", "testdatabase", "admin", "sa")
    but to no avail, nothing happened, it still asked for the database login everytime i generate the report.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: database login

    Moved To Reporting

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: database login

    Here is what I use to set up CR reports

    vb.net Code:
    1. Public Sub outputToPrinter(ByVal mRepName As String, ByVal mstrW As String, Optional ByVal strPars As String = "")
    2.         Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
    3.         Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
    4.         Dim currValue As New CrystalDecisions.Shared.ParameterValues
    5.         'Sub report object of crystal report.
    6.         Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
    7.         'Sub report document of crystal report.
    8.         Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    9.         Dim i, x, z As Integer 'Some Counters
    10.         Dim mRep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    11.  
    12.         Try
    13.             ' Load the report
    14.             'Need to add the Report dll yet nothing works
    15.             Dim rep As New RSMReports.clsReports(mRepName)
    16.             mRep = rep.returnRep()
    17.             mRep.RecordSelectionFormula = mstrW
    18.  
    19.            
    20.             'SQL Server
    21.             ConInfo.ConnectionInfo.UserID = "xxxx"
    22.             ConInfo.ConnectionInfo.Password = "xxxxxxxxi"
    23.             ConInfo.ConnectionInfo.ServerName = mdlGeneral.serverName
    24.             ConInfo.ConnectionInfo.DatabaseName = mdlGeneral.dbName
    25.  
    26.             For i = 0 To mRep.Database.Tables.Count() - 1
    27.                 mRep.Database.Tables(i).ApplyLogOnInfo(ConInfo)
    28.             Next i
    29.  
    30.             'Check for Subreprots
    31.             For i = 0 To mRep.ReportDefinition.Sections.Count - 1
    32.                 For x = 0 To mRep.ReportDefinition.Sections(i).ReportObjects.Count - 1
    33.                     With mRep.ReportDefinition.Sections(i)
    34.                         If .ReportObjects(x).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
    35.                             mySubReportObject = CType(.ReportObjects(x), CrystalDecisions.CrystalReports.Engine.SubreportObject)
    36.                             mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
    37.                             For z = 0 To mySubRepDoc.Database.Tables.Count - 1
    38.                                 mySubRepDoc.Database.Tables(z).ApplyLogOnInfo(ConInfo)
    39.                             Next z
    40.                         End If
    41.                     End With
    42.                 Next x
    43.             Next i
    44.             'Parameter Fields
    45.             If strPars.Trim() <> String.Empty Then
    46.                 Dim arPars As String() = strPars.Split("~")
    47.                 Dim strVal As String()
    48.                 For xx As Integer = 0 To arPars.GetUpperBound(0)
    49.                     strVal = arPars(xx).Split("=")
    50.                     paraValue.Value = strVal(1)
    51.                     currValue = mRep.DataDefinition.ParameterFields(strVal(0)).CurrentValues
    52.                     currValue.Add(paraValue)
    53.                     mRep.DataDefinition.ParameterFields(xx).ApplyCurrentValues(currValue)
    54.                 Next
    55.             End If
    56.             mRep.PrintToPrinter(1, False, 0, 0)
    57.         Catch crExp As CrystalDecisions.CrystalReports.Engine.LoadSaveReportException
    58.             MessageBox.Show("Error printing Report " & mRepName & System.Environment.NewLine & _
    59.                 "The error number is: " & Err.Number.ToString() & System.Environment.NewLine & _
    60.                 "The error Message is: " & System.Environment.NewLine & crExp.Message.Trim(), "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    61.         Catch ex As Exception
    62.             MessageBox.Show("Error printing Report " & mRepName & System.Environment.NewLine & _
    63.                             "The error number is: " & Err.Number.ToString() & System.Environment.NewLine & _
    64.                             "The error Message is: " & System.Environment.NewLine & ex.Message.Trim(), "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    65.         Finally
    66.             mRep.Dispose()
    67.         End Try
    68.     End Sub
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    Re: database login

    Thank you so much, i will study your code and see if it works.

    others are still welcome to help. I will appreciate it. Thank you.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    Re: database login

    I have set my datasource location to (local) thinking it would avoid the problem of looking for server when testing on other pc, however, i am still prompted by that "database login" please help

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    Re: database login

    Hi to all! i have finally solve my problem. for all these headaches, it all boiled down to connections. I have selected sql native client instead of SQLOLEDB. if there are developers out there who would encounter problems like these, you can also check if you chose the correct connections in the database expert for your report in the crystal report. Thank you.

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