Hi try this
Synopsis
A VB .NET application uses Crystal Reports for Visual Studio .NET as the reporting development tool.
How do you pass database logon information to a Crystal Report at runtime in this VB .NET application?
Solution
To pass logon information to a Crystal Report at runtime, use the following code sample:
'Import namespaces in general section
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
'Add the following code above the statement "#Region" to declare the required objects
Dim crReportDocument As New ReportDocument()
Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter
'Add the following code after the statement "InitializeComponent()"
crReportDocument = New CrystalReport1()
'CrystalReport1 is the name given to the strongly typed report that has been added to the 'application. In this case, we are creating a new instance of that report. If you want to work with 'existing reports, you will need to use the 'Load' method of the ReportDocument() object.
'For Example: 'crReportDocument.Load("C:\myReports\myReport.rpt", 'OpenReportMethod.OpenReportByTempCopy)
'Set the ConnectionInfo properties for logging on.
'The ServerName member is either the DSN (if using ODBC) or the physical server name (if using a 'native connection)
With crConnectionInfo
.ServerName = "DSN or Server Name"
.DatabaseName = "DatabaseName"
.UserID = "UID"
.Password = "PWD"
End With
'Set the CrTables to the Tables collection of the report
CrTables = crReportDocument.Database.Tables
'Loop through each table in the report and apply the LogonInfo information
For Each CrTable in CrTables
CrTableLogonInfo = CrTable.LogonInfo
CrTableLogonInfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
'If changing database servers at runtime, you will need to specify the table location similar to the line below:
'CrTable.Location = "the TableName in the report"
CrystalReportViewer1.ReportSource = crReportDocument
=============
NOTE:
If you're using a web application make sure that, you do not specify or call the DataBind in your code as this will nullify the code above.
If you are changing database servers at runtime, it is important that you specify the table location after you apply logon information (this is a case sensitive property). You can either specify the tablename only or the fully qualified tablename such as:
crTable.location = "dbname.dbo.tablename"
=============
To pass database logon information to a Crystal Report at runtime using C#, go to
and search for:
· csharp_win_dbengine.exe
cheers
pgtek