
Crystal Reports and Path to DB
Hello
Quote:
> Can anyone give me guidance as to how (in code) you can change the
database
> a crystal report is pointing to? I found the database property .. but it
> tells me that it is read only.
Here is a sample I found and adapted. It works for me using an Access
database.
Private Sub Report_DefineLogonInfo(ByVal oReport As Object, ByVal
sStoredProcedureName As String, ByVal sDSTableName As String)
' oReport is the report you are editing
' sStoredProcedureName is the name of the stored procedure (or
query) you are using
' sDSTableName is the name of the table you are updating in your
dataset.
Dim oLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
myCrystalReportViewer.LogOnInfo = New
CrystalDecisions.Shared.TableLogOnInfos()
oLogonInfo = New CrystalDecisions.Shared.TableLogOnInfo()
oLogonInfo.TableName = sStoredProcedureName
With oLogonInfo.ConnectionInfo
.ServerName = DBPath ' REPLACE WITH THE PATH TO
YOUR DATABASE
.DatabaseName = ""
.UserID = UserId ' REPLACE WITH YOUR
USERID
.Password = Password ' REPLACE WITH YOUR
PASSWORD
End With
myCristalReportViewer.LogOnInfo.Add(oLogonInfo)
CType(oReport,
CrystalDecisions.CrystalReports.Engine.ReportDocument).SetDataSource(myDatas
et.Tables(sDSTableName))
myCrystalReportViewer.RefreshReport()
End Sub
Here is a sample I found and adapted. It works for me using an Access
database.
If you have several tables in your dataset, you will have to change the
location for all tables of your dataset.
You can have more information at the following URL:
http://www.crystalreportsbook.com/Chapter14.asp (you may be asked for
registration before accessing the page).
Depending the database you are accessing, you will have to set correctly the
ServerName and/or DatabaseName properties, like indicated in the following
table.
Database
ServerName Property
DatabaseName Property
Access
The fully qualified file path
Leave it blank
SQL Server[9]
The server name
The database name
ODBC Driver
The DSN name
Leave it blank
Hope it helps you.
MichaelP