My tnsNames.Ora File -

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = Sonia-PC)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

ORACLR_CONNECTION_DATA = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) 
    ) 
    (CONNECT_DATA = 
      (SID = CLRExtProc) 
      (PRESENTATION = RO) 
    ) 
  ) 

.Net Code -

public partial class Default2 : System.Web.UI.Page
{

    OracleCommand cmd = new OracleCommand();
    OracleConnection conn = new OracleConnection("Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Sonia-PC)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE))),UserID=user_test,Password=sonia;");

    protected void Page_Load(object sender, EventArgs e)
    {
        cmd.CommandText = "INSERTSTUDENT";
        cmd.Connection = conn;
        cmd.Parameters.Add("p_roll", OracleDbType.Long, 64, 1, ParameterDirection.Input);
        cmd.Parameters.Add("p_name", OracleDbType.Varchar2, 2000, "sonia", ParameterDirection.Input);
        cmd.Parameters.Add("p_marks", OracleDbType.Long, 64, "10", ParameterDirection.Input);
        conn.Open();
        cmd.ExecuteNonQuery();
    }
}
`

When the line conn.Open() is executed ERROR is dere -** *ORA-12154: TNS:could not resolve the connect identifier specified* ** My SQL Developer is connected with ORACLE. There is no error in Oracle Set Up.

I have set Data Source = XE also but it also giving the same ERROR.``

Dani AI

Generated

ORA-12154 means the Oracle client could not resolve the connect identifier being used. ’s tnsnames.ora shows an XE alias and is correct that a TNS alias can be used — but that only works if the .NET process can actually find and read the same tnsnames.ora that SQL Developer isn’t necessarily using. SQL Developer often uses its own JDBC connection path, so its success only proves the database is reachable, not that the Oracle client configuration for the web app is correct.

A quick isolation step (avoids tnsnames.ora entirely): use EZCONNECT (host:port/service_name) as the Data Source and confirm basic connectivity. For example:

Data Source=Sonia-PC:1521/XE;User Id=user_test;Password=sonia;

Also test name/port resolution from the same Windows account that runs the app: run tnsping XE and, if available, sqlplus user_test/sonia@XE from a command prompt. These checks show whether the client resolves the alias and whether the DB listener is reachable.

Checklist of the most common causes and fixes:

  • Connection-string syntax: in ADO.NET separate key/value pairs with semicolons (;). A stray comma can make the whole descriptor invalid.
  • tnsnames.ora location: the running Oracle client must see the file (typically under ORACLE_HOME\network\admin or the folder pointed to by TNS_ADMIN).
  • Multiple Oracle homes / PATH order: an unexpected Oracle home on PATH can make the app use a different client that lacks the XE entry. Use where tnsping / search for tnsnames.ora to find which home is active.
  • IIS / service account and environment variables: services pick up environment variables at process start — restart IIS after changes and ensure the app-pool identity has access to the tnsnames file.
  • Bitness mismatch: 32-bit vs 64-bit Oracle client vs app pool must match.
  • Provider behavior: Oracle.ManagedDataAccess and unmanaged ODP.NET locate tnsnames differently; if the managed driver is in use, set TNS_ADMIN for that driver or place tnsnames.ora in the expected location.

A recommended flow: try EZCONNECT to confirm basic connectivity, then fix tnsnames discovery (TNS_ADMIN / ORACLE_HOME / PATH / permissions), restart the app host, and retest the alias. Once the connection is stable, the stored-proc call can be reviewed for parameter usage and error handling.

I think this link can help you

Because on the tnsNames.ora file you already have an XE entry, maybe you only need to declare the connection string as
"Data Source=XE,UserID=user_test,Password=sonia;"

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.