Professional Documents
Culture Documents
Connection Properties
Overview
The Crystal Reports 9 Report Designer Component (RDC) has a number of new
properties and methods available at runtime to connect a report to its data source.
This document provides an in-depth look at each of these new properties and methods.
This document provides a better understanding of how to connect your Crystal Report to
your data sources at runtime.
Contents
INTRODUCTION ......................................................................................................... 2
DETECTING CONNECTION PROPERTIES ..................................................................... 2
Where to Find the Connection Properties ...................................................2
CONNECTING TO A DATA SOURCE USING CONNECTION PROPERTIES ......................... 3
NATIVE CONNECTIONS ............................................................................................. 4
Native – Microsoft Access............................................................................4
Native - Btrieve ............................................................................................5
Native - Oracle.............................................................................................6
ODBC CONNECTIONS .............................................................................................. 7
ODBC – Microsoft Access ...........................................................................7
ODBC - SQL Server.....................................................................................8
ODBC - Oracle ..........................................................................................10
OLE DB CONNECTIONS ......................................................................................... 11
OLE DB – Microsoft Access ......................................................................11
OLE DB - SQL Server................................................................................13
OLE DB - Oracle .......................................................................................14
SETTING DATA SOURCE CONNECTION INFORMATION FOR SUBREPORTS................... 16
WHAT ABOUT OLDER REPORTS? ........................................................................... 17
LISTING OF ATTRIBUTES FOR CONNECTIONINFO OBJECT ......................................... 17
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 1
Report Designer Component Connection Properties
Introduction
In Crystal Reports 9, a new series of database properties were introduced in the report
designer. To incorporate these new properties into the Report Designer Control (RDC), a
new ConnectionProperties collection was created.
The ConnectionProperty Object is a property bag that stores connection information for
the report. Information is dependent on the Crystal Decisions database DLL used by the
report and the database drivers that support the DLL.
For example, a report using an OLE DB (ADO) connection to Microsoft SQL Server will
contain properties supplied by the database DLL (crdb_ado.dll). These properties include
Provider, Data Source, Initial Catalog, User ID, and Password, as well as the properties
supplied by the supporting drivers such as Local Identifier, Connect Timeout and so on.
The values for these properties can be set to connect to the current report data source or
to change the report data source.
NOTE The connection properties shown are in the format “Description: Value Pairs”.
For most properties, the description and name are the same. At runtime the name of the
connection property is required to set a value or add a name value pair.
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 2
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
The following sections detail several common data sources a report can connect to, and
provides code for connecting to that data source or switching to that data type from a
different data source.
Native Connections
This section lists the connection properties available for Microsoft Access, Btrieve, and
Oracle and demonstrates how to connect those data sources through the native drivers.
The following sample code (for a native connection to Microsoft Access, Btrieve and
Oracle) describes how to:
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
Native - Btrieve
Connection Properties:
• Data File
• Data File Search Path
Changing the Btrieve Table Location at Runtime
To change the Btrieve table location at runtime in
Visual Basic 6 use sample code below:
====================
NOTE:
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 5
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
The 'Data File' and 'Data File Search Path' are global report properties. This means that
any changes made to these properties will be applied globally to the report regardless of
what table you retrieved the ConnectionProperties from.
This means if the new table file exists in both the original (path saved with report) as well
as the new
data file location (set in code), the table file will be loaded from the path saved with the
report. To work around this, set the 'Data File Search Path' to a blank string as shown
below.
====================
Report.Database.Tables(1).ConnectionProperties("Data
File Search Path") = ""
Report.Database.Tables(1).Location =
"C:\yourNewPath\Table.DAT"
Report.Database.Tables(1).ConnectionProperties("Data
File") = "C:\yourNewPath\FILE.DDF"
Report.Database.Tables(1).ConnectionProperties("Data
File Search Path") = "C:\yourNewPath\"
Report.Database.Tables(2).Location =
"C:\yourNewPath\Table.DAT"
Native - Oracle
Connection Properties:
• Server
• User ID
• Password
Connecting Oracle (Native) at Runtime
'Declare a Connection Info Object
Dim ConnectionInfo As CRAXDRT.ConnectionProperties
'Set the Connection Info to Connection Properties of ‘the table
object
Set ConnectionInfo =
Report.Database.Tables(1).ConnectionProperties
'Set the server name
ConnectionInfo.Item(“Server”) = “Server name”
'Set the user name
ConnectionInfo.Item(“User ID”) = “User name”
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
ConnectionInfo.Item(“Password”) = “Password”
ODBC Connections
This section lists the connection properties available for Microsoft Access, Microsoft
SQL Server, and Oracle and demonstrates how to connect those data sources through the
ODBC driver.
The following sample code (for an ODBC connection to Microsoft Access, Btrieve and
Oracle) describes how to:
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 7
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
NOTE If the Microsoft Access database has a session level security, this should be setup in the
DSN.
The session level security cannot be passed at runtime.
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 9
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
NOTE If the database uses SQL Authentication and the user has a password, you need to pass
at least the Password to the report. You do not need to specify the DSN, User ID or
Database unless you are attempting to change any of these at runtime.
If the database uses NT Authentication, do not specify the user name or password.
To set the type of authentication set Trusted_Connection to 0 for SQL Authentication or
set Trusted_Connection to 1 for NT Authentication.
ODBC - Oracle
Connection Properties:
• Server
• User ID
• Password
Connecting to Oracle (ODBC) at Runtime
'Declare a Connection Info Object
Dim ConnectionInfo As CRAXDRT.ConnectionProperties
'Set the Connection Info to Connection Properties of the table
object
Set ConnectionInfo =
Report.Database.Tables(1).ConnectionProperties
'Set the ODBC DSN
ConnectionInfo.Item(“DSN”) = “ODBC DSN”
'Set the user name
ConnectionInfo.Item(“User ID”) = “User name”
'Set the password
ConnectionInfo.Item(“Password”) = “Password”
'Set the fully qualified table name if different from 'the
original data source
Report.Database.Tables(1).Location = “schema.tablename”
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 10
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
OLE DB Connections
This section lists the connection properties available for Microsoft Access, Microsoft
SQL Server, and Oracle and demonstrates how to connect those data sources through the
OLE DB driver.
The following sample code (for an OLE DB connection to Microsoft Access, Btrieve and
Oracle) describes how to:
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 11
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 12
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
NOTE If the database uses SQL Authentication and the user has a password, you need to pass
at least the Password to the report. You do not need to specify the DSN, User ID or
Database unless you are attempting to change any of these at runtime.
If the database uses NT Authentication, do not specify the user name or password.
To set the type of authentication set Trusted_Connection to 0 for SQL Authentication or
set Trusted_Connection to 1 for NT Authentication. For an OLEDB connection, you will
need to set "Integrated Security" to 0 or 1 for SQL or NT authentication respectively.
OLE DB - Oracle
Connection Properties:
• Provider
• Data Source
• User ID
• Password
• Locale Identifier
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 14
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
• OLE DB Services
Connecting to Oracle (OLE DB) at Runtime
'Declare a Connection Info Object
Dim ConnectionInfo As CRAXDRT.ConnectionProperties
'Set the Connection Info to Connection Properties of ‘the table
object
Set ConnectionInfo =
Report.Database.Tables(1).ConnectionProperties
'Set the OLE DB Provider
ConnectionInfo.Item(“Provider”) = “SQLOLEDB”
'Set the physical server name
ConnectionInfo.Item(“Data Source”) = “Server name”
'Set the user name
ConnectionInfo.Item(“User ID”) = “User name”
'Set the password
ConnectionInfo.Item(“Password”) = “Password”
'Set the fully qualified table name if different from ‘the
original data source
Report.Database.Tables(1).Location = “schema.tablename”
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 15
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
.DeleteAll
'*******************************************
'Add subreport connection information here as per
'the connection properties appropriate for the
'database connection
'*******************************************
End With
'Set the location of the table in the report to the
'name of the table in the data source
crxSubreport.Database.Tables(1).SetTableLocation _
"", "DBTableName", ""
End If
Next ReportObject
Next crxSection
Once you have a listing of the connection properties, you can set them using the code
samples provided in this document.
Other options include deleting all the connection properties and then adding the name
values pairs for the desired data source connection. Another option is to use the older
methods described in “cr_rdc_dbconnectivity.pdf” to set the connection information.
Download this document from http://support.crystaldecisions.com/docs.
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 17
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 19
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
Use Saved Properties Indicates if user opened report with refresh from
Repository=TRUE. (S)
Repository URI Repository URI. (S, L)
Repository Object Name Repository object name. (S, L)
Author Name of author. (S, L)
Description Select statement. (S)
Refreshed from True if refresh from repository was successful. (L)
Repository
User ID User name required to connect to the data source.
(S, L)
Location Full path for location of repository. (L)
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 21
cr_rdc9_connectionproperties.pdf
Report Designer Component Connection Properties
For reports created before 9, the following are the valid properties of the Attributes
property bag for the ConnectionInfo object:
Key/Attribute Explanation
Database DLL The DLL that is being used to communicate with the database. Applies
to all connections.
URI The URI (Uniform Resource Identifier) or path of the database file.
Applies to Crystal Business Views, Query, and File connections.
Server Type The type of the server. Applies to SQL connections.
Server Name The name of the server. Applies to SQL connections.
Database Name The name of the database being accessed. Applies to SQL connections.
Connection String A string that supplies extra parameters to the SQL server if it needs
them. Applies to SQL connections.
Private Data This string is used to contain additional information that RAS may need
to connect to a specific database. The contents of this string are
dependent on the database driver. Refer to your database documentation
for information on what the driver requires to make a connection. The
following databases use Private Data:
10/21/2004 12:38 PM Copyright © 2003 Crystal Decisions, Inc. All Rights Reserved. Page 22
cr_rdc9_connectionproperties.pdf