ODAC

Connecting in Direct Mode

ODAC Professional Edition allows you to connect to Oracle in two ways: in the Client mode, using Oracle Client software, or in the Direct mode, over TCP/IP. The Direct mode can be enabled using the TOraSession.Options.Direct property.

ODAC Connection Modes

By default, ODAC, like most applications that work with Oracle, uses the Oracle Call Interface (OCI) to connect to the Oracle database server. This is referred to as connecting in the Client mode, and is the usual way to develop Oracle applications with a third-generation language. All OCI routines are stored in external libraries, so the executables for applications that work through OCI are small. However, working through OCI requires Oracle client software to be installed on client machines. It is rather inconvenient and causes additional installation and administration expenses. Furthermore, there are some situations where the installation of Oracle client is not advisable or may be even impossible—for example, if you deploy an application to remote machines that are not overseen by a proficient system administrator.

To overcome these challenges, ODAC Professional Edition includes an option to connect to Oracle directly over the network using the TCP/IP protocol. This is referred to as connecting in the Direct mode. Connecting in the Direct mode does not require Oracle client software to be installed on client machines. The only requirement for running an application that uses ODAC in the Direct mode, is that the operating system must support the TCP/IP protocol.

Connecting in Direct Mode

To connect to Oracle server in the Direct mode, set up your TOraSession instance as follows:

Host is the server's IP address or DNS name.

Port is the port number that the server listens to.

SID is a system identifier that specifies the name of an Oracle database instance.

ServiceName is a system alias for an Oracle database instance (or multiple instances).

Note that the syntax used to set up the Server property in the Direct mode is different from the Client mode. In the Client mode, this property must be set to the TNS name of the Oracle server.

Note that if the port number is followed by a colon, and the service name prefix (sn=) or the SID prefix (sid=) is not defined, then by default, the connection will be established using SID.

An example below illustrates the connection to Oracle in the Direct mode. The IP address of the Oracle server is 205.227.44.44, the port number is 1521 (the most commonly used port for Oracle), and the SID is orcl (standard Oracle SID):

var
  Session: TOraSession;
. . .
Session.Options.Direct := True;
Session.Username := 'Scott';
Session.Password := 'tiger';
Session.Server := '205.227.44.44:1521:orcl'; 
Session.Connect;

connecting to Oracle with Service Name:


...
Session.Server := '205.227.44.44:1521/orcl';
...
or
...
Session.Server := '205.227.44.44:1521:sn=orcl';
...

connecting to Oracle with SID:


...
Session.Server := '205.227.44.44:1521:orcl';
...
or
...
Session.Server := '205.227.44.44:1521:sid=orcl';
...

This is all you need to do to enable the Direct mode in your application. You do not have to rewrite other parts of your code.

To return to the OCI mode, set TOraSession.Options.Direct to False and Session.Server to the TNS name of your server.

You can connect to Multi-Threaded Server using the Direct mode. The server must be configured to use a specific port and the TTC protocol. This can help you avoid firewall conflicts.

Note: The Direct mode is available in ODAC Professional Edition and Oracle Trial Edition. An attempt to set the TOraSession.Options.Direct property to True in ODAC Standard Edition will generate a "Feature is not supported" error.

Client Mode vs Direct Mode

Applications that use the Client mode and those that use the Direct mode have similar performance and file size. In terms of security, using the Direct mode is the same as using Oracle Client without Oracle Advanced Security. In the Direct mode, ODAC uses DES authentication and does not support Oracle Advanced Security.

Advantages of the Direct mode:

Limitations of the Direct mode:

A connection in the Direct mode is managed transparently by an instance of TOraSession, and you can easily switch back to OCI in the Client mode at any time if the above limitations become critical to you.

See Also

© 1997-2024 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback