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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hmznzr
    New Member
    • Dec 2008
    • 4

    #1

    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.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    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.

    Comment

    • OuTCasT
      Contributor
      • Jan 2008
      • 374

      #3
      Changing Database of Crystal Report

      I use a sql query to get the ServerName of the current machine that i am on.

      Code:
       
      Private Sub GetName()
      Dim sqlcon As SqlConnection = New SqlConnection("Server=(local);Data Source=.\sqlexpress;Initial Catalog='" & strCompanyName & "';Integrated Security=True")
      Dim sqlCOm As SqlCommand = New SqlCommand("select @@servername", sqlcon)
      sqlcon.Open()
      strOldServerName = sqlCOm.ExecuteScalar
      sqlcon.Close()
      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.sta rtuppath.

      Code:
       
      Private Sub Report()
      Dim report As New ReportDocument
      Dim connection As IConnectionInfo
      Dim oldServerName As String = "DONOVANPC\SQLEXPRESS"
      Dim oldDatabaseName As String = "PayDay10"
      Dim newServerName As String = strOldServerName
      Dim newDatabaseName As String = strCompanyName
      Dim UserID As String = ""
      Dim Password As String = ""
      
      report.Load(Application.StartupPath + "\Reports\PerksTaxReport.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()
      End Sub

      Comment

      Working...