ASP.NET oracle connection not working in debug mode RRS feed

  • Question

  • User-1344339330 posted

    I have a C# ASP.NET application which connects to an Oracle db.  When i access the site via http://localhost/mysite/ it works fine, but if I enter the site using debug mode in Visual Studio 2008 I get the error 'ORA-12154: TNS:could not resolve the connect identifier specified'.

    The only solutions I can find around this error is the check the tnsnames.ora file - but i'm not sure what i should be checking as it work fine when not in debug mode!  Where am I going wrong?  Is this something to do with 32/64bit issue?



    Tuesday, May 1, 2012 12:27 PM

All replies

  • User1013750657 posted


    im not sure how you are connecting to oracle ....

    what i do is, in my connection string i use the entire block from tnsnames file. this way im never dependent on the oracle configuration.

    all you have to do is make sure you have oracle client well installed.


    here it goes


    using system.data.oracleclient;
    oracleconnection a = new oracleconnection();
    a.connectionstring = "User ID=" + /*your_oracle_user*/ +
                                            ";Password=" + /*your_oracle_password*/ +
                                            ";Data Source=" +
                                            "(DESCRIPTION = " +
                                            "  (ADDRESS = (PROTOCOL = TCP)(HOST = " + /*Your_host_name_or_ipaddress*/ + ")(PORT = 1521)) " +
                                            "  (CONNECT_DATA = " +
                                            "    (SERVER = DEDICATED) " +
                                            "    (SID = " + /*Your_Sid_NAME*/ + ") " +
                                            "  ) " +
    Wednesday, May 2, 2012 3:31 AM
  • User-1344339330 posted

    Not sure that helps as we use a dataaccesslayer class:


    DataAccessLayer.GetOracleDataReader("SELECT * FROM Table", DataAccessLayer.DatabaseConnections.MyConnectionName))


    (DatabaseConnections is an Enum used to access the connection string from the web.config)

    public static OracleCommand CreateOracleCommand(string queryString, DatabaseConnections connectionName)
    OracleConnection oracleCon = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings[connectionName.ToString()].ConnectionString);

    OracleCommand oracleCmd = new OracleCommand(queryString, oracleCon);

    oracleCmd.CommandType = CommandType.Text;

    oracleCmd.CommandTimeout = 900;

    return oracleCmd;


    /// <summary>
    /// Get the data from the database in the form of a OracleDataReader.
    /// </summary>
    /// <param name="connectionName">Connection to use</param>
    /// <returns>OracleDataReader containing the data.</returns>

    public static OracleDataReader GetOracleDataReader(string queryString, DatabaseConnections connectionName)

    //Create the command.

    using (OracleCommand oracleCmd = DataAccessLayer.CreateOracleCommand(queryString, connectionName))

    //Open the connection.


    //Return a datareader of the data.  CommandBehaviour.Closeconnection will force
    //the Oracle connection to be closed when the reader is closed.

    return oracleCmd.ExecuteReader(CommandBehavior.CloseConnection);



    Wednesday, May 2, 2012 6:35 AM
  • User1013750657 posted



    samething just add the conenctionstring to your web.config file

    Wednesday, May 2, 2012 12:15 PM
  • User-1344339330 posted

    OK - done that, same issue!  Ihave read this:


    However I cannot do this as the 'web tab' it refers to is not present on my project!

    Thursday, May 3, 2012 10:32 AM