My Crystal Report is pulling information from a stored procedure I wrote. So everytime I run my application it prompts me for a password for the server. How do I bypass this step and hardcode the password into my application. I don't want my users knowing the password for the server. I am writing in vb.net using visual studio 2008.
Crystal Report connection to SQL vb.net in Visual Studio 2008
Collapse
X
-
-
You need to send the UserID and Password to the report. so it wont ask you for it when u run it.
Code:Dim report As New ReportDocument Dim connection As IConnectionInfo Dim oldServerName As String = ".\SQLEXPRESS" Dim oldDatabaseName As String = "Old DatabaseName" Dim newServerName As String = strOldServerName Dim newDatabaseName As String = strCompanyName Dim UserID As String = "" Dim Password As String = "" report.Load(Application.StartupPath + "\Reports\example.rpt") CrystalReportViewer1.ReportSource = report 'Change the server name and database in main report For Each connection In report.DataSourceConnections report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password) Next 'Change the server name and database subreports Dim subreport As ReportDocument For Each subreport In report.Subreports For Each connection In subreport.DataSourceConnections If (String.Compare(connection.ServerName, oldServerName, True) = 0 _ And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password) End If Next Next CrystalReportViewer1.RefreshReport()
Comment