Connecting Tech Pros Worldwide Help | Site Map

Crystal Report connection to SQL vb.net in Visual Studio 2008

Newbie
 
Join Date: Aug 2008
Location: Orlando, FL
Posts: 13
#1: Jan 7 '09
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.
OuTCasT's Avatar
Needs Regular Fix
 
Join Date: Jan 2008
Location: South Africa
Posts: 353
#2: Jan 15 '09

re: Crystal Report connection to SQL vb.net in Visual Studio 2008


You need to send the UserID and Password to the report. so it wont ask you for it when u run it.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim report As New ReportDocument
  3. Dim connection As IConnectionInfo
  4. Dim oldServerName As String = ".\SQLEXPRESS"
  5. Dim oldDatabaseName As String = "Old DatabaseName"
  6. Dim newServerName As String = strOldServerName
  7. Dim newDatabaseName As String = strCompanyName
  8. Dim UserID As String = ""
  9. Dim Password As String = ""
  10.  
  11. report.Load(Application.StartupPath + "\Reports\example.rpt")
  12. CrystalReportViewer1.ReportSource = report
  13. 'Change the server name and database in main report
  14. For Each connection In report.DataSourceConnections
  15. report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  16. Next
  17. 'Change the server name and database subreports
  18. Dim subreport As ReportDocument
  19. For Each subreport In report.Subreports
  20. For Each connection In subreport.DataSourceConnections
  21. If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
  22. And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
  23. subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  24. End If
  25. Next
  26. Next
  27. CrystalReportViewer1.RefreshReport()
  28.  
Reply

Tags
crystal reports