Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to avoid re-occurring Err "ORA-12154: TNS:could not resolve service name"

How to avoid re-occurring Err "ORA-12154: TNS:could not resolve service name"

Scheduled Pinned Locked Moved ASP.NET
databaseoraclesysadminwindows-adminsecurity
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cs8569
    wrote on last edited by
    #1

    I have 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); db_conn.Open(); string str_sql = "select name_complete from emp_master " + "where emp_no = '" + 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; }

    CA Keer.

    M I 2 Replies Last reply
    0
    • C cs8569

      I have 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); db_conn.Open(); string str_sql = "select name_complete from emp_master " + "where emp_no = '" + 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; }

      CA Keer.

      M Offline
      M Offline
      Member 96
      wrote on last edited by
      #2

      Your issue might be oracle specific, however I've experienced a somewhat similar problem due to connection pooling in Firebird and MS SQL server. You might want to try emptying the connection pool forcefully when you get that exception.

      1 Reply Last reply
      0
      • C cs8569

        I have 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); db_conn.Open(); string str_sql = "select name_complete from emp_master " + "where emp_no = '" + 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; }

        CA Keer.

        I Offline
        I Offline
        Ista
        wrote on last edited by
        #3

        also not calling Dispose on the connection object will not pool the connection

        -------------------------------------------------------- 1 line of code equals many bugs. So don't write any!! My mad coder blog

        C 1 Reply Last reply
        0
        • I Ista

          also not calling Dispose on the connection object will not pool the connection

          -------------------------------------------------------- 1 line of code equals many bugs. So don't write any!! My mad coder blog

          C Offline
          C Offline
          cs8569
          wrote on last edited by
          #4

          I tried your suggession as below but dose not solve the issue. The issue is not related to Oracle i guess. Because everything is same and I only have to reset IIS. Thats restores the database access to normal. try { dbConn.Open(); } catch(Exception ex) { dbConn.Dispose(); }

          CA Keer.

          I 1 Reply Last reply
          0
          • C cs8569

            I tried your suggession as below but dose not solve the issue. The issue is not related to Oracle i guess. Because everything is same and I only have to reset IIS. Thats restores the database access to normal. try { dbConn.Open(); } catch(Exception ex) { dbConn.Dispose(); }

            CA Keer.

            I Offline
            I Offline
            Ista
            wrote on last edited by
            #5

            cs8569 wrote:

            try { dbConn.Open(); } catch(Exception ex) { dbConn.Dispose(); }

            should be: { dbConn.Open(); } catch(Exception ex) { } dbConn.Dispose();

            -------------------------------------------------------- 1 line of code equals many bugs. So don't write any!! My mad coder blog

            C 1 Reply Last reply
            0
            • I Ista

              cs8569 wrote:

              try { dbConn.Open(); } catch(Exception ex) { dbConn.Dispose(); }

              should be: { dbConn.Open(); } catch(Exception ex) { } dbConn.Dispose();

              -------------------------------------------------------- 1 line of code equals many bugs. So don't write any!! My mad coder blog

              C Offline
              C Offline
              cs8569
              wrote on last edited by
              #6

              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.

              CA Keer.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups