ORA-12154 error when connection to Oracle Database from C#


  • I'm trying to connect to an Oracle Database 9.0.2 using OracleClient in C#.
    I get the error "ORA-12154 Could not resolve service name" when trying to connect to the database.

    I've checked the TNSNAMES.ora file an it seems ok.
    The project where I get this error was previously a .VS 2003 project which I converted to a VS 2005 project.

    As a test I created a small project in VS 2005 where I connected to the same Oracle database with the same connection parameters, and it worked fine.

    Does anyone have a clue on what might be the problem?



    Friday, March 31, 2006 12:41 PM

All replies

  • Do you have multiple Oracle installations on your machines like Oracle client and Developer ?

    If so you'll have to set up the tnsnames.ora on both HOMES.
    Or else setup the registry.

    Set the values of TNS_ADMIN to the folder where the tnsnames.ora you set up resides.

    Eg. C:\oracle\ora92\admin
    Friday, March 31, 2006 6:22 PM
  • Thank you for your reply.
    I only have one instance of the tnsnames.ora file, and I only have the Oracle Client installed.
    I'm still strugglig with this, but it seems to be related to only one of the projects in the solution.
    When I set another project as startup project, there is no trouble connecting to the database and getting data in a datatable. But from this one project I get message as I mentioned before.

    I'm quite clueless at this point. Any more Ideas?





    Thursday, April 06, 2006 8:12 AM
  • Then it must be a bug in your code. Investegate the stack-trace of the exception and recheck the code you use to connect.
    Thursday, April 06, 2006 8:19 AM
  • Hi Trond,

    Did PJ's suggestion help you?
    Since the problem is project specific, I think you may try to recreate a new project and add the code block one by one to isolate the problem.

    If you still have any concern, please feel free to post here.

    Best regards,
    Peter Huang

    Tuesday, April 11, 2006 2:09 AM
  • Try creating a new entry in the tns using the (crappy) oracle tool (oracle net manager). Ive had this same problem before and fixed it this way.

    Tuesday, April 11, 2006 2:30 PM
  • guys

    even I have an application on vs2003 which gives the same error. I am able to connect to the db using sql+ but the application is not able to do so. I developed another application to check on this and is connecting. Any suggestions on what the problem might be.

    Monday, April 24, 2006 8:11 AM
  • I am having similar issues

    I am trying to connect to Oracle9i from my .Net 1.1 Web App with the code block below ...

    OracleConnection oracleConn = new OracleConnection();
    oracleConn.ConnectionString = "User Id=abcdef;Password=xyz;Data Source=Ram_Dev";

    I am using the following entry below in my TNSNAMES.ORA file

    Ram_Dev =
        (ADDRESS_LIST =
            (ADDRESS = (PROTOCOL = TCP) (Host = oradb10) (Port = 1574))
        (CONNECT_DATA =
          (SID = oradev)

    Now, let me explain where I stand ...
    1. I am able to connect to the Oracle DB from my machine using PL/SQL developer ...
    2. I am able to connect to the Oracle DB from .Net 1.1 when creating a WINDOWS Application

    3. When I create a Web Application from .Net 1.1, it gives me the below mentioned error ...
    " ORA-12154: TNS:could not resolve service name "

    I have already tried various diff ways to fix this, but it has not been fruitful. Few things i already did (i) Given read and execute permissions for various users to the ORACLE dir, (ii) Made a TNS_ADMIN entry to the registry settings ORACLE with value to the C:/ORACLE/ora92/network/ADMIN

    Kindly help. Have already spent 2 full days trying to fix this

    Tuesday, November 07, 2006 5:55 PM
  • Hey Ram,

    Did you restart the IIS. Try doing that.



    Wednesday, November 08, 2006 3:24 AM
  • Manu,
    I tried to Re-start IIS but that did not help ... :(

    To all others having this issue,

    Now I tried to un-install Oracle Client 9.2 and re-install it

    And later saw a new Error as mentioned below:
    System.Data.OracleClient requires Oracle client software version 8.1.7 or greater "

    Then I was looking for ways to fix this issue and finally found one to solution ...

    To FIX the above issue while using .Net 1.1 (VS 2003) & Oracle Client 9.2 (9i), to make an Oracle Connection from ASP .Net 1.1 Appliation (using System.Data.OracleClient.OracleConnection ) :: please do the following -

    1. Go to your MACHINE.CONFIG file (location: "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG")
    2. Search for text "<processModel" which is the process model Attributes section
    3. In the processModel string,
    try to add user name as system ( userName="system" )

    This worked miracles for me. 3 days of non-stop troubleshooting, finally found one solution :) ... Hope it helps you ...

    Please drop your comments if the soln did help you ...

    Wednesday, November 08, 2006 7:09 PM
  • I. some more common explaination for the above issue, I found on the web ...

    System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.

    When usign System.Data.OracleClient with Oracle9i client, i got the following message while connecting to the Oracle database from and ASP.NET application.

    System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.

    Security permissions were not properly set when the Oracle 9i Release 2 client was installed on Windows with NTFS. The result of this is that content of the ORACLE_HOME directory is not visible to Authenticated Users on the machine; this again causes an error while the System.Data.OracleClient is communicating with the Oracle Connectivity software from an ASP.NET using Authenticated User privileges.

    To fix the problem you have to give the Authenticated Users group privilege to the Oracle Home directory.

    • Log on to Windwos as a user with Administrator privileges.
    • Start Window Explorer and navigate to the ORACLE_HOME folder.
    • Choose properties on the ORACLE_HOME folder.
    • Click the “Security” tab of the “Properties” window.
    • Click on “Authenticated Users” item in the “Name” list.
    • Uncheck the “Read and Execute” box in the “Permissions” list under the “Allow” column.
    • Re-check the “Read and Execute” box under the “Allow” column
    • Click the “Advanced” button and in the “Permission Entries” verify that “Authenticated Users” are listed with permission = “Read & Execute”, and Apply To = “This folder, subfolders and files”. If not, edit that line and make sure that “Apply To” drop-down box is set to “This folder, subfolders and files”. This should already be set properly but it is important that you verify it.
    • 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.
    • Reboot, to assure that the changes have taken effect.
    Wednesday, November 08, 2006 9:51 PM

    This problem may occur if you had installed oracle earlier.


    After spending more than a day, I figured that the final solution to this problem is to Reinstall Oracle client in a differnt folder Wink


    Instead of D:\oracle\ora92.. give any other path





    Thursday, October 11, 2007 8:07 AM
  • My scenario is very much similar to the original post:

    -SqlPlus works

    -Toad works

    -But using c# code and microsoft's OracleClient class does not work. Fails in code where I do "connection.Open()" with the ORA-12154 error.


    What fixed the problem for me:

    -Went to my %ORACLE_HOME%\NETWORK\ADMIN folder

    -There was a SQLNET.ORA file in this folder. I simply removed it. Now all that this folder had was my TNSNAMES.ORA

    Then my c# application worked.


    PS: Also, I don't know if this makes a difference or not, but I happenned to copy over my TNSNAMES.ORA into the

    %ORACLE_HOME%\NETWORK\ADMIN\SAMPLES folder as well (overwriting the default tnsnames.ora file that comes with the installation). I also left the SQLNET.ORA file in the SAMPLES folder untouched.


    Hope this helps folks !

    Thursday, January 24, 2008 3:39 PM
  • Try this-----------------


    Oracle_Home :C:\oracle\product\10.2.0\db_1

    Oracle_Base : C:\oracle\product\10.2.0\client_1

    Add some string in Registry edit

    Create the registry key that the installer is looking for to verify Oracle is installed.  (Make sure you do not replace valid keys, but if the following do not exist the install will not work.)

    "Oracle in OraHome92"="Installed"

    -------------------------- And let me know........
    Thursday, April 17, 2008 10:35 AM
  • Look at the TNSNames.ora file.

    If you have one more installation, be sure which one you are using.


    If you are using directory naming:

    • Verify that "LDAP" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).
    • Verify that the LDAP directory server is up and that it is accessible


    If you need detailed error information, please visit


    Best Regards


    Tuesday, November 25, 2008 3:02 PM
  • The following solution could apply to this problem

     I was trying to use Reporting Services from my Report Server to connect to an Oracle instance.  

    I can:
    - tnsping the Oracle instance
    - Connect to Oracle instance via TOAD
    - Connect to the Oracle instance from Visual Studio data source
    - Connect to the Oracle instance from Visual Studio report preview

    However, once I deployed the report to my report server, when I tried to access the report.  I will get the ORA-12154 error

    After looking at multiple places online, and performing numerous testings, the following 3 components are essential to solve this problem.  The ORA-12154 error will occur if any one of the following steps are missing

    Step 1:  (As mentioned by RAM in previous post) Reapply Read Write and Execute permission to the Oracle_Home folder. e.g. Go to C:\oracle\product\10.2.0\client_1
    Right Click on the client_1 folder
    Select Properties
    Click Security
    Click Authenticated Users
    Check Read, Write, Read & Execute
    Click Apply
    Wait for a minute for completion
    Click OK

    Step 2:  In C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN, create/edit the sqlnet.ora file with the following (As opposed to a previous post of deleting the sqlnet.ora, the sqlnet.ora is essential):


    ## for example



    Step 3: In C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN, edit the tnsnames.ora, so that the instance name includes the above mentioned


    instead of

    OracleInstance =


        (ADDRESS = (PROTOCOL = TCP)(HOST = = 1234))



    The entry should be:

    OracleInstance.WII.WINDOWS.MICROSOFT.cOM =


        (ADDRESS = (PROTOCOL = TCP)(HOST = = 1234))



    Also, verify from regedit that ORACLE_HOME is pointing to the correct place, e.g. C:\oracle\product\10.2.0\client_1

    Hope This Helps

    lbjohn99 at yahoo dot com
    Wednesday, December 10, 2008 8:21 PM