#docslug#/ecob/ecob/V1.1.0/establish-a-connection At present, OceanBase Embedded SQL in C (ECOB) uses the CONNECT statement of the extended SQL statements to create connections to OceanBase Database.
Syntaxes:
Syntax 1: EXEC SQL CONNECT <:username> identified by <:password> (using <:dbstring>)
Syntax 2: EXEC SQL CONNECT <:user_password> (using <:dbstring>)

Descriptions of the variables:
<:username>: Specifies the username used to connect to the OceanBase Database tenant in Oracle mode. The username follows the test@oracle format, for example, test@oracle. If OBProxy is used for connection, the cluster name must be added. In this case, the username follows the username@tenant name#cluster name format, for example, test@oracle#cluster1.
<:password>: Specifies the password used to connect to the OceanBase Database tenant in Oracle mode.
<:dbstring>: Specifies the service name used to connect to the OceanBase Database tenant in Oracle mode. This service name is the name of the string in the tnsnames.ora file specified in the TNS_ADMIN environment variable. Assume that you have the following connection string in the tnsnames.ora file specified in the TNS_ADMIN environment variable:
demo= (DESCRIPTION= (ADDRESS=(PROTOCOL = TCP)(HOST = 10.10.10.10)(PORT = 30035)) (CONNECT_DATA= (SERVICE_NAME=TEST)) )Then, the value of <:dbstring> is demo. If the string follows the ip+port pattern, the <:dbstring> value can be written as 'ip:port/dbname', for example, '10.10.10.10:30035/test'.
<:user_password>: Specifies the username and password used to connect to the OceanBase Database tenant in Oracle mode, for example, test@oracle/welcome1. The username is separated from the password with a forward slash (/).
Sample statement used to create a connection by using syntax 1:
char * username ="**u***";
char * password = "**1***";
char * servicename = "**s***";
EXEC SQL CONNECT :username identified by :password using :servicename;
Sample statement used to create a connection by using syntax 2:
char * userpass = "**1***";
char * servicename = "**s***";
EXEC SQL CONNECT :userpass using :servicename;