Click to See Complete Forum and Search --> : Change database connection for existing report***RESOLVED***
Halon
Jun 28th, 2003, 10:56 AM
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
Halon
Jun 28th, 2003, 11:30 AM
I think i found a way to do it but i am getting an error.
In the report viewer i have this code
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'========================================================================
'Create an instance of the strongly-typed report object
crReportDocument = New rptEmployees()
'Setup the connection information structure to be used
'to log onto the datasource for the report.
crConnectionInfo = New ConnectionInfo()
With crConnectionInfo
.ServerName = "65.XXX.XX.XX" 'physical server name
.DatabaseName = "xxxxxxxx"
.UserID = "xxxxxx"
.Password = "xxxxxxxxx"
End With
'Get the table information from the report
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables
'Loop through all tables in the report and apply the connection
'information for each table.
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
'Set the viewer to the report object to be previewed.
CrystalReportViewer1.ReportSource = crReportDocument
'========================================================================
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?
Halon
Jun 29th, 2003, 10:30 AM
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.
Dim myDataSet As dsSingleQuotation
Dim myDataAdapter As SqlDataAdapter
Dim cnn As SqlConnection = New SqlConnection(LocalConnString)
Dim myCommand As SqlCommand = New SqlCommand("Select * from infoTrack_Quotation where IsInvoice = 0", cnn)
myCommand.CommandType = CommandType.Text
myDataSet = New dsSingleQuotation()
cnn.Open()
myDataAdapter = New SqlDataAdapter(myCommand)
Try
myDataAdapter.Fill(myDataSet, "infoTrack_Quotation")
Catch
MsgBox("Database Error. Error number: " & Err.Number & ": Description: " & Err.Description, MsgBoxStyle.Exclamation, "Database Error")
End Try
cnn.Close()
' This is the Crystal Report file created at Design Time
Dim oRpt As New rptQuotationsByCategoryNoDetail()
' Set the SetDataSource property of the Report to the Dataset
oRpt.SetDataSource(myDataSet)
' Set the Crystal Report Viewer's property to the oRpt Report object that we created
CrystalReportViewer1.ReportSource = oRpt
hope this can help someone else!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.