Skip to Main Content
  • Questions
  • .NET Core Connection String to RAC database

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Geraldo.

Asked: April 18, 2019 - 11:43 am UTC

Last updated: April 06, 2020 - 12:20 am UTC

Version: 18.4.0

Viewed 1000+ times

You Asked

Hello, Ask Tom Team.

We have a .Net Core app connecting to a Oracle 18c RAC database. We are not using tnsnames.ora file (there is no oracle client installed on the client-server side). We are using managed .Net Core oracle client and the following connection string (easy method):

"Data Source=db-scan:1521/dbname;User Id=user;Password=pwd;Min Pool Size=1;Max Pool Size=60;Connection Lifetime=180;Connection Timeout=60;Incr Pool Size=5; Decr Pool Size=1;Pooling=true;Load Balancing=true;HA events=true;".

We do not know if this is the right way.

I have read an Oracle note: https://docs.oracle.com/en/database/oracle/oracle-database/18/rilin/about-connecting-to-an-oracle-rac-database-using-scans.html#GUID-090555EB-7EB7-44DE-BD06-54FED5CF5712

They say:

...Instead, applications must use an Oracle Net connect descriptor with the following format:

(DESCRIPTION =
(CONNECT_TIMEOUT=90) (RETRY_COUNT=20)(RETRY_DELAY=3) (TRANSPORT_CONNECT_TIMEOUT=3)
( ADDRESS = (PROTOCOL = TCP)(HOST=scan)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=service_name)))

If this is correct, how can I specify settings such as : Pooling, Load Balancing, HA events... like the connection string we are actually using?

What is the recommended method to connect to an Oracle 18c RAC database from a .Net Core app?

Thanks in advanced.

Regards,

and Connor said...

All of that information "(description=" is probably most easily placed inside a tnsnames.ora and then that can be used in the .Net connection string.

For example, I have the following in my tnsnames.ora file on my local PC (under XX\network\admin) where "XX" is where Oracle client is installed.

mydb =
  (DESCRIPTION=
    (ADDRESS=
      (PROTOCOL=TCP)
      (HOST=xxx.yyy.com)
      (PORT=1525)
    )
    (CONNECT_DATA=
      (SERVICE_NAME=pdb1)
    )
  )


Then in my .Net connection, all I need do is:

Data Source=mydb;User Id=user;Password=pwd;....


and the details for "mydb" are collected from tnsnames.ora

Just as an aside, the (commonly used) practice of:

Min Pool Size=1;Max Pool Size=nn

is typically a bad idea. If you can handle a pool size of 'nn' (which seems very large!) then why aggressively try push that back down to 1 over time. You'll get better performance if those sessions are allowed to persist, with something like:

Min Pool Size=xx;Max Pool Size=xx+a little bit

where 'xx' is slightly more than the *typical* number of connections you expect.

Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Follow Up

Geraldo Peralta, April 29, 2019 - 3:58 pm UTC

I got what you told me about using a tnsnames.ora connection

1. What do you mean when you say "number of connections" (where I can see them because is not the same as sessions)?

2. Where do I specify parameters like Pooling=true;Load Balancing=true;HA events=true;"? I read it is a good practice to use these parameters in RAC databases using SCAN. What do you think?
Connor McDonald
April 30, 2019 - 2:30 am UTC

They still go in your .Net connection.

FollowUp

Geraldo Peralta, May 02, 2019 - 11:43 am UTC

OK.

What do you mean when you say "number of connections" (where I can see them because is not the same as sessions)?
Connor McDonald
May 13, 2019 - 3:20 am UTC

I mean concurrent active usages of the database.

Lets says 1000 users equates to

- *average* 12 people using a database session at any given instant
- *peak* 17 people

A common config people will set is easy:

min=1,max=20

or

min=12,max=20

But if are saying that your database can handle up to 20, then you may as well remove the cost of connection/session allocation and deallocation by just doing:

min=20,max=20


Follow Up

Geraldo, April 03, 2020 - 6:56 pm UTC

You said
"Lets says 1000 users equates to
- *average* 12 people using a database session at any given instant
- *peak* 17 people"

1. Where do I see that *average* 12 people using a database session?
2. Does it mean people currently connected?
3. How can I count it?
4. I am using pooling and in order to set Min Pool Size and Max Pool Size according to my database usage, should I count the number of sessions in v$sessions under the application user connected to database?
Connor McDonald
April 06, 2020 - 12:20 am UTC

The database will capture a critical statistic here for you. "Average Active Sessions".

Here's a great slide deck on the background and importance of that statistic

https://www.slideshare.net/jberesni/average-active-sessions-rmoug2007-37554537

Note that "connected sessions" is not the same as "active sessions". Active is someone doing something on the database *right now*, not just sitting there connected.


Follow Up

Geraldo, April 06, 2020 - 1:16 am UTC

Thanks, Connor.

I will check it out.

More to Explore

Multitenant

Need more information on Multitenant? Check out the Multitenant docs for the Oracle Database