Results 1 to 7 of 7

Thread: How to change DSN at run time

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784

    Question How to change DSN at run time

    Dear All,

    I am using VB6+ CR9, how to change DSN at run time? ..

    Please help

    TIA

    Winanjaya

  2. #2
    Addicted Member
    Join Date
    Sep 2005
    Posts
    163

    Re: How to change DSN at run time

    Have you found the answer to this question? .... I would like to know too
    chilling

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784

    Re: How to change DSN at run time

    not yet


  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: How to change DSN at run time

    Quote Originally Posted by Winanjaya
    Dear All,

    I am using VB6+ CR9, how to change DSN at run time? ..

    Please help

    TIA

    Winanjaya
    I don't understand your question, could you elaborate?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    Addicted Member
    Join Date
    Sep 2005
    Posts
    163

    Re: How to change DSN at run time

    This is how to change DSN at runtime:
    From the CrystalReport.New event which you will find in the CrystalRepost.vb file add the following line:
    Code:
    Public Sub New()
            MyBase.New()
            Logon(Me, "DSN Name", "Database", "UserName", "Password")
        End Sub
    then create a module within your appliaciation call "modCrystalReports" and add the following code
    Code:
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    
    Module modCrystalRports
    
        ''' <summary>
        ''' The Logon method iterates through all tables 
        ''' </summary>
        ''' <param name="cr"></param>
        ''' <param name="server"></param>
        ''' <param name="db"></param>
        ''' <param name="id"></param>
        ''' <param name="pass"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public 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
            Return True
        End Function
        ''' <summary>
        ''' Apply Login
        ''' </summary>
        ''' <param name="cr"></param>
        ''' <param name="ci"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function ApplyLogon(ByVal cr As ReportDocument, ByVal ci As ConnectionInfo) As Boolean
    
            Dim li As TableLogOnInfo
            Dim tbl As Table
    
            ' for each table apply connection info 
            For Each tbl In cr.Database.Tables
                li = tbl.LogOnInfo
                li.ConnectionInfo = ci
                tbl.ApplyLogOnInfo(li)
    
                ' check if logon was successful 
                ' if TestConnectivity returns false,
                ' check logon credentials 
                If (tbl.TestConnectivity()) Then
                    'drop fully qualified table location
                    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 Module
    That should do it
    chilling

  6. #6
    Junior Member
    Join Date
    Aug 2007
    Posts
    24

    Re: How to change DSN at run time

    how to handle multi user application...in vb6.0/sql 2000
    i want to restrict other users when one user is editing the one record say Invoice. no. 0001

  7. #7
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: How to change DSN at run time

    Quote Originally Posted by udaywalve
    how to handle multi user application...in vb6.0/sql 2000
    i want to restrict other users when one user is editing the one record say Invoice. no. 0001

    I think you posted to the wrong thread, becuase you can't edit any data via Crystal Reports.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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