Results 1 to 3 of 3

Thread: Change database connection for existing report***RESOLVED***

  1. #1

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228

    Change database connection for existing report***RESOLVED***

    I have a vb.net app with a bunch of reports that were set up using the wizard and work fine on the machine set up on the server because all database fields are connecting locally to the sql server database on the machine). (my station so is no problem)

    Problem is now if i want to install the app on other clients machines i need to be able to programmatically change the connection string. I wrote the code for the program so i was just going to compile a new version for all other machines with the connection string for the server but i have no idea where to change it in code.

    Anyone have any ideas or help?
    Thanks in advance
    Last edited by Halon; Jun 29th, 2003 at 10:31 AM.
    Soylent Green tastes like chicken

  2. #2

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    I think i found a way to do it but i am getting an error.
    In the report viewer i have this code

    VB Code:
    1. Public Sub New()
    2.         MyBase.New()
    3.  
    4.         'This call is required by the Windows Form Designer.
    5.         InitializeComponent()
    6.  
    7.         'Add any initialization after the InitializeComponent() call
    8.  
    9.         '========================================================================
    10.  
    11.         'Create an instance of the strongly-typed report object
    12.         crReportDocument = New rptEmployees()
    13.  
    14.         'Setup the connection information structure to be used
    15.         'to log onto the datasource for the report.
    16.         crConnectionInfo = New ConnectionInfo()
    17.         With crConnectionInfo
    18.             .ServerName = "65.XXX.XX.XX"    'physical server name
    19.             .DatabaseName = "xxxxxxxx"
    20.             .UserID = "xxxxxx"
    21.             .Password = "xxxxxxxxx"
    22.         End With
    23.  
    24.         'Get the table information from the report
    25.         crDatabase = crReportDocument.Database
    26.         crTables = crDatabase.Tables
    27.  
    28.         'Loop through all tables in the report and apply the connection
    29.         'information for each table.
    30.         For Each crTable In crTables
    31.             crTableLogOnInfo = crTable.LogOnInfo
    32.             crTableLogOnInfo.ConnectionInfo = crConnectionInfo
    33.             crTable.ApplyLogOnInfo(crTableLogOnInfo)
    34.         Next
    35.  
    36.         'Set the viewer to the report object to be previewed.
    37.         CrystalReportViewer1.ReportSource = crReportDocument
    38.         '========================================================================
    39.  
    40.     End Sub

    All login info is correct but i keep getting prompted for the username and password (which is correct in the code). I enter it and it still says login failed.

    Anyone?
    Soylent Green tastes like chicken

  3. #3

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    K, i figured out a different way. I just set the report source to be a dataset that i can modify however i like.
    Here is a simple example i used.
    VB Code:
    1. Dim myDataSet As dsSingleQuotation
    2.         Dim myDataAdapter As SqlDataAdapter
    3.  
    4.         Dim cnn As SqlConnection = New SqlConnection(LocalConnString)
    5.         Dim myCommand As SqlCommand = New SqlCommand("Select * from infoTrack_Quotation where IsInvoice = 0", cnn)
    6.  
    7.         myCommand.CommandType = CommandType.Text
    8.         myDataSet = New dsSingleQuotation()
    9.         cnn.Open()
    10.  
    11.         myDataAdapter = New SqlDataAdapter(myCommand)
    12.  
    13.         Try
    14.             myDataAdapter.Fill(myDataSet, "infoTrack_Quotation")
    15.  
    16.         Catch
    17.             MsgBox("Database Error. Error number: " & Err.Number & ": Description: " & Err.Description, MsgBoxStyle.Exclamation, "Database Error")
    18.         End Try
    19.  
    20.         cnn.Close()
    21.  
    22.         ' This is the Crystal Report file created at Design Time
    23.         Dim oRpt As New rptQuotationsByCategoryNoDetail()
    24.  
    25.         ' Set the SetDataSource property of the Report to the Dataset
    26.         oRpt.SetDataSource(myDataSet)
    27.  
    28.         ' Set the Crystal Report Viewer's property to the oRpt Report object that we created
    29.         CrystalReportViewer1.ReportSource = oRpt

    hope this can help someone else!
    Soylent Green tastes like chicken

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width