3.2.2 Use the ore.connect and ore.disconnect Functions
The examples in this section demonstrate the various ways of specifying an OML4R connection to an Oracle Database instance.
The examples use sample values for the ore.connect
argument values. Replace the sample values with the appropriate values for connecting to your database.
Example 3-1 Using ore.connect and Specifying a SID
This example invokes the ore.connect
function and specifies the user
, sid
, host
, password
, and port
arguments.
ore.connect(user = "oml_user", sid = "sales", host = "sales-server", password = "oml_userStrongPassword", port = 1521 )
Example 3-2 Using ore.connect and Specifying a Service Name
This example demonstrates using a service name rather than a SID. It also specifies connecting to the local host.
ore.connect(user = "oml_user", host = "localhost", password = "oml_userStrongPassword", service_name = "sales.example.com")
Example 3-3 Using ore.connect and Specifying an Easy Connect String
This example uses the conn_string
argument to specify an easy connect string that identifies the connection.
ore.connect(user = "oml_user", password = "oml_userStrongPassword", conn_string = "sales-server:1521:sales (ADDRESS=(PROTOCOL=tcp) (HOST=sales-server) (PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=sales.example.com)))")
Example 3-4 Using ore.connect and Specifying a Full Connection String
This example uses the conn_string
argument to specify a full connection string that identifies the connection.
ore.connect(user = "oml_user", password = "oml_userStrongPassword", conn_string = "DESCRIPTION= (ADDRESS=(PROTOCOL=tcp) (HOST=sales-server) (PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=myserver.example.com))")
Example 3-5 Using the conn_string Argument to Specify an Oracle Wallet
This example uses the conn_string
argument to specify an Oracle wallet. The mydb_test
string is the connection identifier for the Oracle database. The Oracle wallet contains the information needed to create the connection. For information on creating an Oracle wallet for an OML4R connection, see Oracle Machine Learning for R Installation and Administration Guide.
ore.connect(conn_string = "mydb_test")
Example 3-6 Using the conn_string Argument and Specifying an Empty Connection String
This example uses an empty connection string to connect to the local host.
ore.connect(user = "oml_user", password = "oml_userStrongPassword", conn_string = "")
Example 3-7 Using the conn_string Argument in Connecting to a Pluggable Database
This example connects to a pluggable database using the conn_string
argument to specify a service name.
ore.connect(conn_string = "pdb1.example.com")
Example 3-8 Using the service_name Argument in Connecting to a Pluggable Database
This example invokes ore.connect
using a service name, host name, and port number to connect to a pluggable database.
ore.connect(service_name = "pdb1.example.com", host = "mypdb", port = 1521)
Example 3-9 Disconnecting an OML4R Session
This example explicitly disconnects an OML4R session from an Oracle database.
ore.disconnect()
Parent topic: Use OML4R with an On-Premises Oracle Database