|
I have created a CR in Visual Studio 2010, and during creation I point to a server and database. To prevent that you get a dialog during runtime, you set the database credentials before the CR is loaded like this:
Rapport.SetDatabaseLogon("UserId", "Password")
The question now is: what if you want to connect to the same database but stored on another server? According to the books I read, the said use something like this:
Rapport.SetDatabaseLogon("UserId", "Password", "localhost\SQLEXPRESS2008", "database")
But this does not work!!! I'm getting the 'Database Login' dialog, where the serverTextbox and databaseTextbox are filled with the servername and databasename I used during creation of the report. According to the official guide CR 2008 the connection information is stored in the rpt-file. But how can I access this and change the connInfo? Is there anyone who can help me?
Thanks
|
|
I have found the solution.
Imports CrystalDecisions
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Configuration
Imports System.Data.SqlClient
Imports CrystalDecisions.Shared
Imports System.Data
Public Class frmPrintWorkorder
Dim decomposeConnString As New SqlConnectionStringBuilder
Dim connString As String
Private Sub frmPrintWorkorder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim crTableLogonInfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crTables As Tables = Nothing
Dim crTable As Table = Nothing
connString = ConfigurationManager.ConnectionStrings("name in app.config").ConnectionString
decomposeConnString.ConnectionString = connString
Dim userId As String = decomposeConnString.UserID
Dim password As String = decomposeConnString.Password
Dim server As String = decomposeConnString.DataSource
Dim database As String = decomposeConnString.InitialCatalog
Dim security As Boolean = decomposeConnString.IntegratedSecurity
Dim Rapport As Werkbon = Me.Werkbon1
Rapport.SetDatabaseLogon(userId, password)
With crConnectionInfo
.ServerName = server
.DatabaseName = database
.UserID = userId
.Password = password
.IntegratedSecurity = security
End With
crTables = Rapport.Database.Tables
For Each crTable In crTables
crTableLogonInfo = crTable.LogOnInfo
crTableLogonInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogonInfo)
Next
End Sub
End Class
|