Dear All,
I am using VB6+ CR9, how to change DSN at run time? ..
Please help
TIA
Winanjaya
Printable View
Dear All,
I am using VB6+ CR9, how to change DSN at run time? ..
Please help
TIA
Winanjaya
Have you found the answer to this question? .... I would like to know too :)
not yet :(
:confused:
I don't understand your question, could you elaborate?Quote:
Originally Posted by Winanjaya
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:
then create a module within your appliaciation call "modCrystalReports" and add the following codeCode:Public Sub New()
MyBase.New()
Logon(Me, "DSN Name", "Database", "UserName", "Password")
End Sub
That should do it :)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
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
Quote:
Originally Posted by udaywalve
I think you posted to the wrong thread, becuase you can't edit any data via Crystal Reports.