2012-02-08 23 views
0

私はしかし、私たちのアプリケーションは、OracleとMSSQLSERVERの両方をサポートしている多くの How to catch SQLServer timeout exceptionsキャッチのOracleタイムアウト例外

のように、他のSQL例外とは異なるタイムアウト例外を処理します。

解決策は理想的にはSystem.Data.OracleClientとOracle.DataAccess.Clientの両方のプロバイダをカバーします。

これらによってスローされる例外のエラーコードは何ですか?

答えて

0

これは私がこれに類似していたになってしまったものです:

しかし、タイムアウトのerrorCodeが

/// <summary> 
    ///  Catches network problems for oracle connections and clears the session pool of invalid connections 
    /// </summary> 
    /// <param name="ex"></param> 
    /// <param name="triedBefore"></param> 
    /// <returns></returns> 
    private bool reconnectOracle(DbException ex) 
    { 
     var exType = ex.GetType(); 
     if (exType.FullName == "Oracle.DataAccess.Client.OracleException") 
     { 
      dynamic exOra = ex; 
      int errorNo = exOra.Number; 
      // Check for oracle network error numbers 
      if (errorNo == 03113 || 
       errorNo == 03114 || 
       errorNo == 03135) // **Timeout seems to be 01013** 
      { 
       AL.Warn("Connection is broken. Error number: {0}. Attempting reconnect.", errorNo); 
       // Network error, close connection 
       Command.Connection.Close(); 

       // All connections in the pool are probably invalid. Ensure that all connections are cleared 
       dynamic con = new StaticMembersDynamicWrapper(Command.Connection.GetType()); 
       con.ClearAllPools(); 

       // Ensure that new connection object is given 
       Command.Connection = null; 

       return true; 
      } 
     } 
     return false; 
    } 

StaticMembersDynamicWrapperであるように思わで説明したように:http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx

私はOracleアセンブリを参照したくないので、代わりにこれを使用しました。

0

使用方法void setQueryTimeout(int seconds)throws SQLException;が動作する可能性があります。 Oracle JDBCドライバで実行されるすべてのSQLに対してスレッド作成が行われる可能性があるため、注意して使用してください。

/** 
* Sets the number of seconds the driver will wait for a 
* <code>Statement</code> object to execute to the given number of seconds. 
* If the limit is exceeded, an <code>SQLException</code> is thrown. A JDBC 
* driver must apply this limit to the <code>execute</code>, 
* <code>executeQuery</code> and <code>executeUpdate</code> methods. JDBC driver 
* implementations may also apply this limit to <code>ResultSet</code> methods 
* (consult your driver vendor documentation for details). 
* 
* @param seconds the new query timeout limit in seconds; zero means 
*  there is no limit 
* @exception SQLException if a database access error occurs, 
* this method is called on a closed <code>Statement</code> 
*   or the condition seconds >= 0 is not satisfied 
* @see #getQueryTimeout 
*/ 
void setQueryTimeout(int seconds) throws SQLException; 
+0

私はJavaではなく、タイムアウトの設定は問題ではありません。問題はタイムアウトに反応しています。 –

+0

非常に申し訳ありませんが、私のせいです、私は気づいていませんでした。ネットの部分 – gokhant

関連する問題