简体   繁体   中英

Oracle Fast Connection Failover not working for ODP.NET. Getting Connection Request Timeout Error

I am using ODP.NET for my MVC project and keep getting "-1000 Connection Request Timeout Error" when the Database goes down and then comes back up again. It starts working as soon as I recycle IIS AppPool. I tried to use ClearAllPool(), ClearPool(connection) inside the catch block to remove the error connection but both didn't work. I found a post on StackOverflow to use Fast Connection Failover by adding HA events=true in the connectionstring. I tried that too but no luck. I asked DBA and they said the feature is ON the server-side by default. I don't know why ODP.NET is still using an old invalid connection created when the database was down even if database is up and running? All of my code is also wrapped inside a using block which will close/dispose connection. My Oracle.DataAccess version is 12.1.0. I read every page on google about the connection pooling, FCF but nothing helped.

my connectionstring is as follow:

<add name="XXX"; providerName="Oracle.DataAccess.Client"; connectionString="DataSource=XXX;username=xxx;password=XXX;Pooling=True;Connection Timeout=120; Connection LifeTime=120; Validate Connection=True; Min Pool size=1;Max Pool size=180; HA events=true; Incr Pool size=5; Decr Pool size=2;"/>

here is my oracle connection code:

using(OracleConnection conn= new OracleConnection(connectionstring))
{
    try
   {
      OracleCommand cmd=new OracleCommand("storedprocedure",conn) 
      {CommandType=CommandType.StoredProcedure};
      //add parameters to command
        foreach(var parmeter in parameters)
        {
        cmd.Parameters.Add(parameter);
        }
        conn.Open(); // this is where exception occurs

        cmd.ExecuteNonQuery();

    }
   catch(OracleException ex)
   {
     if(conn.State=ConnectionState.Open)
     {
      conn.Close();
      conn.Dispose();
     }

     //log exception ex in logfile

   }

      if(conn.State=ConnectionState.Open)
      {
       conn.Close();
       conn.Dispose();
      }
}
//Dispose All Parameters using Dispose() outside using statement.
foreach(var parmeter in parameters){
parameter.Dispose();
}

The only solution work is when I set Pooling=False, which we don't want to do.

I played with these connectionstring properties like increase Min pool size, increase connection Lifetime etc. but nothing seems to be working.

I will really appreciate any help here.

Thank you.

Try this and tell me if you still have this issue

using(OracleConnection conn= new OracleConnection(connectionstring))
using(OracleCommand cmd=new OracleCommand("storedprocedure",conn))
{
    cmd.CommandType=CommandType.StoredProcedure;
    foreach(var parmeter in parameters)
    {
        cmd.Parameters.Add(parameter);
    }
    conn.Open(); // this is where exception occurs
    cmd.ExecuteNonQuery();
}

if error is not desired put this entire block into try/catch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM