How to avoid re-occurring Err "ORA-12154: TNS:could not resolve service name" (not a common oracle connection issue)
I made a web application which uses oracle database. Below is the minimum code which explains how I am accessing the data.
At a time the application working fine and I can access and do everything with database. Some other time database server is down for scheduled maintenance. If I try to run the application at this point of time it will raise err "ORA-12154: TNS:could not resolve service name"
(I'm catching this exception and displaying a custom error message to users). After some hours the database server is up an running.
Now if I run the application it should behave normal and give database access. But it dose not, and continue to give the same ORA-12154" error.
In such case I have to reset IIS to make the application work normal. So the question is how to avoid re-occurring Err "ORA-12154".
private string get_name()
{
string name = "no name";
string conn_str = "Provider=MSDAORA.1;Persist Security Info=True;Data Source=test;User ID=test;Password=test";
OleDbConnection db_conn = new OleDbConnection(conn_str);
try
{
db_conn.Open();
string str_sql = "select NAME from ess_users " +
"where EMPNO = '" + TextBox1.Text + "'";
OleDbCommand db_cmd = new OleDbCommand(str_sql, db_conn);
OleDbDataReader db_reader = db_cmd.ExecuteReader();
while (db_reader.Read())
{
name = db_reader[0].ToString();
}
db_reader.Close();
db_conn.Close();
return name;
}
catch
{
db_conn.Dispose();
return name;
}
} // end

How to avoid re-occurring Err "ORA-12154: TNS:could not resolve service name" (not a common oracle connection issue)
BitShift
Well it has to do with the data access mechanism. .NET doesn't know anything about Oracle TNS configuration issues. When you stop and start IIS you're terminating the thread your application is executing under and unloading anything currently in use that is related to Oracle with respect to your app.
If I had to take a wild guess I would suspect a corrupt OLEDB connection pool. You could test this theory by adding "OLE DB Services = -2;" to your connection string (disabling resource pooling) and see if the TNS error still occurs.
ISUTri
follwing is the entry in TNSNAMES.ORA FILE
TEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 100.80.100.105)(PORT = 1333))
(CONNECT_DATA = (SID = TST))
)
Thanks for trying to help me. But please note "the application working fine and I can access and do everything with database. for some reson it goes down, I do not change anything anywhere, only thing i do is reset IIS." therefor I say that its not a oracle issue. it is something to do with setting/confuguration in .dotnet.
Asday
From Oracle's MetaLink:
Problem Description
-------------------
When running an application using the Oracle9i Release 2 (9.2.0.1.0) install
of client software and that attempts to connect to an Oracle database with the
Authenticated User privilege (such as when you use Microsoft's Internet
Information Server (IIS)) through any of the following programmatic interfaces
1. Oracle Provider for OLE DB
2. Microsoft OLE DB Provider for Oracle
3. Oracle ODBC Driver
4. Microsoft ODBC for Oracle
5. Oracle Objects for OLE (OO4O)
6. Microsoft .NET Framework Data Provider for Oracle
you may receive one of the following errors:
(1) Oracle Provider for OLE DB
(a) Error Type: Microsoft OLE DB Service Components (0x80070005)
Access is denied.
(b) OraOLEDB.Oracle Provider is not registered on the local machine
(2) Microsoft OLE DB Provider for Oracle
(a) Error Type: Microsoft OLE DB Provider for Oracle (0x80004005)
Oracle client and networking components were not found. These
components are supplied by Oracle Corporation and are part of the
Oracle Version 7.3.3 or later client software installation. Provider
is unable to function until these components are installed.
(b) Error Type: Microsoft OLE DB Provider for Oracle (0x80004005)
Oracle error occurred, but error message could not be retrieved
from Oracle.
(3) Oracle ODBC Driver
(a) Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
Specified driver could not be loaded due to system error 5 (Oracle
in OraHome92).
(4) Microsoft ODBC for Oracle
(a) The Oracle(tm) client and networking components were not found.
These components are supplied by Oracle Corporation and are part
of the Oracle Version 7.3 (or greater) client software installation.
You will be unable to use this driver until these components have
been installed.
(b) Error number: -2147467259
Error Description: [Microsoft][ODBC Driver Manager] Driver's
SQLAllocHandle on SQL_HANDLE_ENV failed
(5) Oracle Objects for OLE
(a) while using a GLOBAL.ASA file
Error Type: Active Server Pages (0x0)
An error occurred while creating object 'OraSession'.
(b) not using a GLOBAL.ASA file
Error Type: Microsoft VBScript runtime (0x800A0046)
Permission denied: 'CreateObject'
(6) Microsoft .NET Framework Data Provider for Oracle
(a) System.DllNotFoundException: Unable to load DLL (oci.dll).
at System.Data.OracleClient.DBObjectPool.GetObject(Boolean&
isInTransaction)
at System.Data.OracleClient.OracleConnectionPoolManager.
GetPooledConnection(String encryptedConnectionString,
OracleConnectionString options, Boolean& isInTransaction)
at System.Data.OracleClient.OracleConnection.OpenInternal
(OracleConnectionString parsedConnectionString, Object transact)
at System.Data.OracleClient.OracleConnection.Open()
at WCWSItemAvailability.ETAAvailability.SingleAvailability(String
ItemNumber, String BusinessUnit, Int32 OrderQty, Int32&
AvailableQty, Int32& OnHandQty, String& ETADate, Int32& Error)
at WCWSItemAvailability.ETAAvailability.XMLAvailability(String
XMLInput)
(7) Other miscellaneous errors
(a) The Specified Module Could Not Be Found
(b) ORA-00604: error occurred at recursive SQL level 1
ORA-12705: invalid or unknown NLS parameter value specified
(c) Unable to load DLL (OraOps9.dll):
...
[DllNotFoundException: Unable to load DLL (OraOps9.dll).]
(d) System Error 998 trying to run ASP page
Solution Description
--------------------
Oracle 9.2 Client software requires that you give the Authenticated User
privilege to the Oracle Home by following these steps:
1. Log on to Windows as a user with Administrator privileges.
2. Launch Windows Explorer from the Start Menu and and navigate to the
ORACLE_HOME folder. This is typically the "Ora92" folder under the
"Oracle" folder (i.e. D:\Oracle\Ora92).
3. Right-click on the ORACLE_HOME folder and choose the "Properties" option
from the drop down list. A "Properties" window should appear.
4. Click on the "Security" tab of the "Properties" window.
5. Click on "Authenticated Users" item in the "Name" list (on Windows XP
the "Name" list is called "Group or user names").
6. Uncheck the "Read and Execute" box in the "Permissions" list under the
"Allow" column (on Windows XP the "Permissions" list is called
"Permissions for Authenticated Users").
7. Re-check the "Read and Execute" box under the "Allow" column (this is
the box you just unchecked).
8. Click the "Advanced" button and in the "Permission Entries" list make
sure you see the "Authenticated Users" listed there with:
Permission = Read & Execute
Apply To = This folder, subfolders and files
If this is NOT the case, edit that line and make sure the "Apply onto"
drop-down box is set to "This folder, subfolders and files". This
should already be set properly but it is important that you verify this.
9. Click the "Ok" button until you close out all of the security properties
windows. The cursor may present the hour glass for a few seconds as it
applies the permissions you just changed to all subfolders and files.
10. Reboot your computer to assure that these changes have taken effect.
Re-execute the application and it should now work.
Explanation
-----------
If you install Oracle9i Release 2 (9.2.0.1.0) on a computer running Windows
with an NTFS partition, the contents of ORACLE_HOME directory will not be
visible to users who are authenticated on that machine. These permissions
were not set properly when the software was installed.
Applications that were working fine with previous versions of Oracle software
will stop working when they upgrade to Oracle 9.2.
NOTE: The application will continue to work if the user has logged onto the
machine as an Administrator.
Any application that is using the Authenticated User privilege will not work.
A notable example would be IIS which might service some of the requests based
on the Authenticated User privileges.
To demonstrate the problem in further detail, you can log on to the operating
system as an authenticated machine user. You won't be able browse the contents
of the ORACLE_HOME directory demonstrating your inability to load any Oracle DLLs
or make a connection.
Additional Information
----------------------
The above error messages may not only be encountered when using Oracle 9.2
client software but may also exists when running into general permissions
issues using third party products on a Windows platform.
charles C
Actually this is very likely an Oracle configuration/network problem. Is your TNSNAMES.ORA database (host) entry pointing to a server name or an IP address
LTD
Yes, connection pooling is recommended. I just wanted to verify that your issue wasn't being caused by a corrupt connection pool.
Changing the userName entry to System will cause the ASP.NET worker process to run under the SYSTEM identity, which means that it has access to just about all of the resources on the computer. With respect to security, that may not be a good thing if your system is accessible from the Internet.
I'm not really sure what resource is being accessed that would fix the TNS error problem. Were read and execute permissions for authenticated users and the ASPNET (Win2K) or NetworkService (Win2003) account granted on the Oracle Home folder
Cem DEMiRKIR
Sorry Sir, joining after a long. was too busy finishing a project.
I do not understand how to check permissions grants Could you please explain me how to check that
WoodPeckerKing
For your info. I am a novice in both asp.net and programming field.
As per MSDN Note "To deploy high-performance applications, you need to use connection pooling. When you use the .NET Framework Data Provider for OLE DB, you do not need to enable connection pooling because the provider manages this automatically."
The connection will establish if "db_conn.Open();" is successfull. (The Err hits at this line) If its not successful that means there is no connection and I dont need to close or dispose it
However I still tried what you have suggested. I also tried using OleDbDataAdapter believing that it will manage the connection its own and I dont need to take care of closing or disposing the connection. But both approches did not solve the problem.
But there is one solution I accidentally found for this problem for which I am not sure if its the correct way For your reference it is given below. However I'm still looking for the correct solution for this problem.
In machine.config file if I change the attribute from userName="machine" to userName="SYSTEM"
Following is the WHOLE TAG
<processModel enable="true" timeout="Infinite" idleTimeout="Infinite" shutdownTimeout="0:00:05" requestLimit="Infinite" requestQueueLimit="5000" restartQueueLimit="10" memoryLimit="60" webGarden="false" cpuMask="0xffffffff" userName="machine" password="AutoGenerate" logLevel="Errors" clientConnectedCheck="0:00:05" comAuthenticationLevel="Connect" comImpersonationLevel="Impersonate" responseDeadlockInterval="00:03:00" maxWorkerThreads="20" maxIoThreads="20"/>
Carver42
Thanks Paul,
I've just put a new 11g client installation on a new IIS server and then migrated a working web site over to it from the old server. I kept running into the ORA-1254 issue and came across your message while troubleshooting.
The 'authenticated user' issue still seems to plague 11g. Anyways, thanks for the detailed post way back in 2006.
Jason