470,585 Members | 1,655 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,585 developers. It's quick & easy.

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

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
2 2012
9,735 Expert Mod 8TB
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
374 256MB
I use a sql query to get the ServerName of the current machine that i am on.

Expand|Select|Wrap|Line Numbers
  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
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
  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 = ""
  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
Jan 15 '09 #3

Post your reply

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

Similar topics

4 posts views Thread by Grant Stanley | last post: by
1 post views Thread by Nathan Bloomfield | last post: by
3 posts views Thread by route_coder | last post: by
2 posts views Thread by deejayquai | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.