Connect (Method)

Applies To:

Connection object, MetaDataConnection object

Description:

Establishes a connection to the database using the criteria set in the connection object. (The Connection object represents either an Interactive Reporting database connection file (OCE) or the connection to a database that is associated ultimately with a specific query section, or less commonly, a specific data model section.)

The Connect method optionally relies on the GetCredentials argument that precedes Release 8.2 credential information.

GetCredentials Argument

The GetCredentials argument provides backward compatibility for users who need to make connections using a script created before Release 8.2. The GetCredentials argument takes a Boolean value.

When the GetCredentials argument is used in the Designer/Explorer application, you are prompted to supply the user ID and password, and optionally a database name. The prompt is the same one used when the user interface requests credentials, such as when you click the Process button and the connection status is disconnected.

If the GetCredentials argument is false when the Connect () method is invoked, whatever credentials have been supplied with the Username property together with a call to the Connection's SetPassword() method are used to establish the connection. If no credentials have been explicitly supplied by these means, you get a standard database error. When the GetCredentials parameter is used in the Web-based client applications, the credentials for the user are obtained following the rules established by the Foundation and by the publishers of the Interactive Reporting database connection file (OCE) and Interactive Reporting document file (BQY) content. For example, if the Interactive Reporting database connection file associated with the query is set to prompt the user when the Interactive Reporting document file was published, you are prompted; if at publishing time the credentials were supplied (Specify Now), then those credentials are used, and so on.

The GetCredentials parameter by default is false. This parameter is persisted as part of a script; it is not saved with the Interactive Reporting document file, and when anInteractive Reporting document file is opened, it is set to its default value. The user must explicitly change the setting of GetCredentials if need be before calling the Connect (Method).

Syntax:

Expression.Connect([optional] Boolean GetCredentials)

Expression Required:

An expression that returns a Connection object

Example 1:

This example shows how to establish a connection with a database using the connection object:

MyConnection = ActiveDocument.Sections["Query"].DataModel.Connection
MyConnection.Open("c:\\OCEs\\SampleDB.oce")
MyConnection.Username = "hyperion"
MyConnection.SetPassword("hyperion")
MyConnection.Connect(true)

Example 2:

This example shows how to use the Disconnect (Method) to disconnect the current connection, and connect to another database. The Disconnect (Method) is available for Designer only:

// < disconnects the current connection
if (ActiveDocument.Sections["Query"].DataModel.Connection.Connected == true)
{
ActiveDocument.Sections["Query"].DataModel.Connection.Disconnect()
}
else
{
// < connect to another database 
MyConnection = ActiveDocument.Sections["Query"].DataModel.Connection MyConnection.Open("c:\\OCEs\\myNewSalesOCE.oce") 
MyConnection.Connect(true) 
}