By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,304 Members | 3,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,304 IT Pros & Developers. It's quick & easy.

is their any dynamic way to set my database location to the report.

P: 4
i am using b.net 2005. i am generating a crystal report. but when i work in a different computer i have to set the location of the database of the report before i generate. is their any dynamic way to set my database location to the report.
Jan 14 '09 #1
Share this Question
Share on Google+
2 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Use a variable to store the database location.
Implement a way to let the user specify the database location and store what they have entered into the variable....use this variable to indicate which database the report should be run on.
Jan 14 '09 #2

OuTCasT
100+
P: 374
I use a sql query to get the ServerName of the current machine that i am on.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub GetName()
  3. Dim sqlcon As SqlConnection = New SqlConnection("Server=(local);Data Source=.\sqlexpress;Initial Catalog='" & strCompanyName & "';Integrated Security=True")
  4. Dim sqlCOm As SqlCommand = New SqlCommand("select @@servername", sqlcon)
  5. sqlcon.Open()
  6. strOldServerName = sqlCOm.ExecuteScalar
  7. sqlcon.Close()
  8. End Sub
  9.  
Once i have done that then i can change the server for the report before its loaded on the crystal report viewer.
What i did in the oldDatabaseName is use the databaseName that i created the report on, seems to get a problem if u dont do this.
All you do is set the location of ur report. You will see i have my in my application.startuppath.

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

Post your reply

Sign in to post your reply or Sign up for a free account.