Elton Stoneman

  Home  |   Contact  |   Syndication    |   Login
  120 Posts | 0 Stories | 3607 Comments | 0 Trackbacks

News

Archives

Post Categories

[Source: http://geekswithblogs.net/EltonStoneman]

The typical approach for connecting to Oracle data sources using ODP.NET is to use a named source in the connection string and rely on the name being resolved through SQLNAMES.ORA and TNSNAMES.ORA:

app.config:

  <connectionStrings>

    <add name="XYZ" connectionString="Data Source=XYZ.WORLD;User ID=xyz;Password=xyz;"/>

  </connectionStrings>

TNSNAMES.ORA:

XYZ.WORLD =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (LOAD_BALANCE = off)

      (FAILOVER = on)

      (ADDRESS_LIST =

        (LOAD_BALANCE = on)

        (FAILOVER = on)

        (ADDRESS = (PROTOCOL = TCP)(HOST = XYZ1-1.internal.xyz.org.uk)(PORT = 1522))

        (ADDRESS = (PROTOCOL = TCP)(HOST = XYZ1-2.internal.xyz.org.uk)(PORT = 1522))

      )

      (ADDRESS_LIST =

        (LOAD_BALANCE = on)

        (FAILOVER = on)

        (ADDRESS = (PROTOCOL = TCP)(HOST = XYZ2-1.internal.xyz.org.uk)(PORT = 1522))

        (ADDRESS = (PROTOCOL = TCP)(HOST = XYZ2-2.internal.xyz.org.uk)(PORT = 1522))

      )

    )

    (CONNECT_DATA =

      (SERVICE_NAME = XYZ)

      (FAILOVER_MODE =

        (TYPE = select)

        (METHOD = basic)

        (RETRIES = 16)

        (DELAY = 1)

      )

    )

  )

 

This is fine until you upgrade your Oracle client, or have multiple instances – if the wrong TNSNAMES gets picked up you’ll get error ORA-12514: TNS:could not resolve the connect identifier specified, and it can be fiddly to track down.

A neater way is to put the whole set of service details in the connection string, avoid the named identifier and circumvent TNSNAMES.ORA altogether:

<connectionStrings>

    <add name="XYZ" connectionString="Data Source=(DESCRIPTION =

    (ADDRESS_LIST =

      (LOAD_BALANCE = off)

      (FAILOVER = on)

      (ADDRESS_LIST =

        (LOAD_BALANCE = on)

        (FAILOVER = on)

        (ADDRESS = (PROTOCOL = TCP)(HOST = XYZ1-1.internal.xyz.org.uk)(PORT = 1522))

        (ADDRESS = (PROTOCOL = TCP)(HOST = XYZ1-2.internal.xyz.org.uk)(PORT = 1522))

      )

      (ADDRESS_LIST =

        (LOAD_BALANCE = on)

        (FAILOVER = on)

        (ADDRESS = (PROTOCOL = TCP)(HOST = XYZ2-1.internal.xyz.org.uk)(PORT = 1522))

        (ADDRESS = (PROTOCOL = TCP)(HOST = XYZ2-1.internal.xyz.org.uk)(PORT = 1522))

      )

    )

    (CONNECT_DATA =

      (SERVICE_NAME = UVASA)

      (FAILOVER_MODE =

        (TYPE = select)

        (METHOD = basic)

        (RETRIES = 16)

        (DELAY = 1)

      )

    )

  );User ID=xyz;Password=xyz;"/>

  </connectionStrings>

Service details contain the whole of the TNSNAMES entry following the identifier (i.e. from DESCRIPTION= onwards), and can span multiple lines in the config file.

Incidentally, if you’re not using ODP.NET in favour of the Microsoft’s framework Oracle provider, System.Data.OracleClient, consider migrating as it will be deprecated from .NET 4.0.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Thursday, November 05, 2009 10:03 PM

Feedback

# re: Avoiding TNSNAMES in Oracle .NET data connections 11/29/2009 5:46 PM Colin Morris
That works fine if you've got one or two applications; but when you've got hundreds of applications connecting to a massive variety of oracle databases, you'll find the tnsnames file makes your life a lot easier for upgrades, server errors, system re-routes and the like.

I much prefer having the DBAs update one location and everything changes than having to individually update every application for what is essentially a configuration change.

# re: Avoiding TNSNAMES in Oracle .NET data connections 5/26/2010 5:39 AM home security systems13
It sounds like a great application.I am pretty much pleased with your good work.Thanks a lot for sharing.Keep up the good works.

# re: Avoiding TNSNAMES in Oracle .NET data connections 7/8/2010 7:38 AM scrapbook pages554
Valuable information and excellent design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!!

# re: Avoiding TNSNAMES in Oracle .NET data connections 10/20/2010 3:12 AM diabetes
I must say that elements you put here look awesome. I liked all of them. Keep it up. Thanks a lot for sharing.... Looking forward to reading your next post..


# re: Avoiding TNSNAMES in Oracle .NET data connections 11/19/2010 7:42 AM h1n1 virus
There is obviously a lot to know about this. I think you made some good points in Features also.
Keep working ,great job!

# re: Avoiding TNSNAMES in Oracle .NET data connections 1/7/2011 8:30 AM medieval times coupon
I am developing an application in VB .NET and Oracle 8i. I am exactly not sure about what provider should I use for my database. Which one would give the best performance... Any help would be appreciated. Thanks.

# re: Avoiding TNSNAMES in Oracle .NET data connections 5/13/2011 11:56 PM advanced seo
great info by the way

# re: Avoiding TNSNAMES in Oracle .NET data connections 6/5/2011 12:37 AM London Escorts
Thanx for the post, we will come back to see if you have any more interesting follow up topics ;-) London escorts Indian

# re: Avoiding TNSNAMES in Oracle .NET data connections 6/25/2011 4:17 AM motorcycle battery
Your tips are extremely valuable. I am pretty much pleased with your good work. Looking forward to reading your next insightful posts.

# re: Avoiding TNSNAMES in Oracle .NET data connections 9/2/2011 4:10 AM roger
wow great i have read many articles about this topic and every time i learn something new i dont think it will ever stop always new info , Thanks for all of your hard work!
ipad 2 keyboard case


# Nice 11/20/2011 12:43 PM Estudiar ingles en el extranjero

I wish more people would write sites like this that are actually interesting to read. With all the fluff floating around on the net, it is a great change of pace to read a site like yours instead.


# re: Avoiding TNSNAMES in Oracle .NET data connections 11/22/2011 11:22 AM sony
Thanks for this amazing share.. this post helped me a lot in my project.. Great work.. scrabble cheat

# Info 11/23/2011 12:33 PM ATL Escorts

This is strange thing.Your observation is fine from one corner if we see things.Lots of people do have this view but things are like that.


# re: Avoiding TNSNAMES in Oracle .NET data connections 12/13/2011 5:30 PM unlock iphone
These techniques are quite useful.I never thought we can do things in this way.Hats off to your brain.I would like to share this on my blog.

# re: Avoiding TNSNAMES in Oracle .NET data connections 12/14/2011 8:33 AM booklet printing
This code is going to useful for me for my next project. thanks for sharing it.

# re: Avoiding TNSNAMES in Oracle .NET data connections 12/16/2011 12:37 PM Jamie Sanger
I am just learning oracle,after finishing it will pursue .net.
Its my second month learning it. You know what i learned very important things with this program.I became a regular user of this site.And i am excited to see many such programs which are simply piece of a master.

# re: Avoiding TNSNAMES in Oracle .NET data connections 12/22/2011 10:18 PM Santo Kitanik
How to upgrade to oracle client i find some errors and is there any other way to avoid TNSNAMES.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: