Search code examples
c#oraclevisual-studiooracle12coracle-manageddataaccess

Connecting to an Oracle Database in a C# Windows application with ManagedDataAccess using Bequeath Protocol


I'm attempting to use a Visual Studio C# Windows Application that connects to a local Oracle 12.2 database (using Oracle.ManagedDataAccess.Client) using the Bequeath protocol so that I don't have to go through the Oracle listener since this is just for a local database connection.

I know that sqlplus natively uses the Bequeath protocol when not specifying a connect string or TNS entry:

sqlplus scott/tiger

*connected* 

The SID and service_names are both "mydb":

select instance from v$thread;
-----
mydb

show parameter service_names;
VALUE
-----
mydb

I can also use the Bequeath protocol when connecting through SQL Developer (using the connection type of Local/Bequeath).

However, I have been unable to find an example of using Bequeath in a connection string that works (at least for me).

The 12.1 documentation for Oracle Net Services isn't really helpful. It gives an overview of Bequeath without any examples.


tnsnames.ora:

MYDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = MYDB)
    )
  )

MYDB_BEQ = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = BEQ)(PROGRAM = oracle)(ARGV0 = oracleMYDB)
      )
    )
    (CONNECT_DATA = (SID = MYDB)
    )
  )

The following works using TCP (which goes through the listener):

new OracleConnection(@"User Id=scott; Password=tiger
;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(
HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)
(SERVICE_NAME=MYDB)))");

*connected*

Or using the TNSNAMES entry:

new OracleConnection("User Id=scott;Password=tiger;Data Source=MYDB")

*connected*

I can connect through TNSNAMES using the above BEQ entry using SQLPLUS:

sqlplus scott/tiger@mydb_beq

*connected*

However, I can't seem to get this to work through Oracle.ManagedDataAccess:

new OracleConnection(@"User Id=scott; Password=tiger
                                      ;Data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = BEQ)(PROGRAM = oracle)(ARGV0 = oracleMYDB)))(CONNECT_DATA = (SID = MYDB)))")

ORA-12533: Network Session: Connect transport address syntax error

Also tried this to use the TNSNAMES entry that worked above:

new OracleConnection("User Id=scott;Password=tiger;Data Source=MYDB_BEQ")

ORA-12533: Network Session: Connect transport address syntax error

I'm probably missing something basic here, but i'm not sure what else to try...


Solution

  • It doesn't look like that is possible.

    In the dataSources Section of the 12c Data Provider for .NET Developer's Guide:

    No bequeath (beq) support. Default address is instead TCP loopback with port 1521 and Oracle service name from environment (ORACLE_SID)