Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is contents of tnsnames.ora cached in C# using Oracle.ManagedDataAccess.dll

Daniel Overby HansenAug 15 2016 — edited Aug 16 2016

I have developed a Windows service in C#, obviously meaning the program is running continuously. Further, the service is making connections to databases using Oracle.ManagedDataAccess.dll. If a new alias is added to the tnsnames.ora file, and the program tries to use that specific alias, it will fail with "ORA-12154: TNS:could not resolve the connect identifier specified". If our service is then restarted, it can connect to the database without problems. It appears that the contents of the tnsnames.ora file is only read once per execution - which is quite unfortunate for a Windows service.

I reproduced the problem with a simple console application which connects to a database using a TNS alias in a loop. I could edit the file while the program is running, and it didn't apply to the running program

var aliases = new List<string> { "FOO.world", "BAR.world" };

for (var i = 0; i < 10; i++) {

     foreach (var alias in aliases) {

          try {

               var connstring = "Data Source=" + alias + ";User Id=*;Password=*;Pooling=False;Connection Timeout=120";

               var conn = new OracleConnection(connstring);

               conn.Open();

               Console.WriteLine(alias.PadRight(20) + "OK");

          } catch (Exception e) {

               Console.WriteLine(alias.PadRight(20) + e.Message);

          }

     }

     Thread.Sleep(5*1000);

}

If you start making changes to tnsnames.ora during the execution, you should be able to reproduce the problem.

Can you change the behavior of the apparent caching of the tnsnames.ora file? Or is it a bug?

Version: 4.121.2.0

Run time version: v4.0.30319

Target platform: .NET 4

Platform: x64

Regards,

Daniel

This post has been answered by Mark Williams on Aug 15 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 13 2016
Added on Aug 15 2016
2 comments
1,438 views