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