Example #1
0
        public virtual DBResult Execute(QueryString sql, DatabaseParameterList parms)
        {
            DatabaseConnection connection;
            DBResult           result = GetConnection(out connection);

            if (result.ResultCode == DBResult.Result.Success)
            {
                /** do actual work in derived class */
                result = Execute(connection, sql, parms);
                if (result.ResultCode == DBResult.Result.ConnectionDropped)
                {
                    /** If the connection was lost during the query, we will perform retry logic */
                    int retriesLeft = connection.ConnectionRetries;

                    do
                    {
                        Log.LogText(LogLevel.WARNING, "The connection was found to be dropped - will retry {0} of {1}", retriesLeft, connection.ConnectionRetries);

                        /** lose the old connection and obtain a new one */
                        if (connection != null)
                        {
                            _connectionPool.DropConnection(connection);
                        }

                        if ((result = GetConnection(out connection)).ResultCode == DBResult.Result.Success)
                        {
                            result = Execute(connection, sql, parms);
                        }
                        else
                        {
                            connection = null;
                        }
                        if (connection.ConnectionRetryInterval != TimeSpan.Zero)
                        {
                            Thread.Sleep(connection.ConnectionRetryInterval);
                        }
                    } while (result.ResultCode == DBResult.Result.ConnectionDropped && --retriesLeft > 0);
                }
            }

            /** connection will be null in the case that we couldn't get one on a retry */
            if (connection != null)
            {
                if (result.ResultCode == DBResult.Result.Exception)
                {
                    Log.LogText(LogLevel.ERROR, "Dropping connection due to Execute exception");
                    _connectionPool.DropConnection(connection);
                }
                else
                {
                    ReleaseConnection(connection);
                }
            }
            LastResult = result;
            return(result);
        }
Example #2
0
 public virtual DBResult Execute(DatabaseConnection conn, QueryString sql, DatabaseParameterList parms)
 {
     throw new NotImplementedException("Execute not implemented in base class");
 }