How to avoid re-occurring Err "ORA-12154: TNS:could not resolve service name"
-
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 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 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.
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
-
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
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 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.
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
-
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
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.