protected override SessionStateItem GetExclusive(String id)
        {
            Debug.Trace("SessionStateClientManager", "Calling Sql GetExclusive, id=" + id);

            bool               usePooling = true;
            SessionStateItem   item;
            SqlStateConnection conn = GetConnection(ref usePooling);

            try {
                item = DoGet(id, conn._cmdTempGetExclusive);
            }
            catch {
                conn.Dispose();
                throw;
            }

            ReuseConnection(ref conn, usePooling);
            return(item);
        }
        protected override void ResetTimeoutAsyncWorker(String id)
        {
            Debug.Trace("SessionStateClientManager", "Calling Sql ResetTimeout, id=" + id);

            bool usePooling         = true;
            SqlStateConnection conn = GetConnection(ref usePooling);

            try {
                conn._cmdTempResetTimeout.Parameters[0].Value = id + s_appSuffix;
                conn._cmdTempResetTimeout.ExecuteNonQuery();
            }
            catch (Exception e) {
                conn.Dispose();
                throw new HttpException(
                          HttpRuntime.FormatResourceString(SR.Cant_connect_sql_session_database),
                          e);
            }

            ReuseConnection(ref conn, usePooling);
        }
        void DisposeOrReuseConnection(ref SqlStateConnection conn, bool usePooling) {
            try {
                if (conn == null) {
                    return;
                }

                if (usePooling) {
                    conn.ClearAllParameters();
                    _partitionInfo.StoreResource(conn);
                    conn = null;
                }
            }
            finally {
                if (conn != null) {
                    conn.Dispose();
                }
            }
        }
        protected override void SetAsyncWorker(String id, SessionStateItem item,
                                               byte[] buf, int length, bool inStorage)
        {
            SqlCommand cmd;

            Debug.Trace("SessionStateClientManager", "Calling Sql Set, id=" + id);

            bool usePooling         = true;
            SqlStateConnection conn = GetConnection(ref usePooling);

            try {
                if (inStorage)
                {
                    Debug.Assert(item.streamLength > 0, "item.streamLength > 0");
                    if (length <= ITEM_SHORT_LENGTH)
                    {
                        if (item.streamLength <= ITEM_SHORT_LENGTH)
                        {
                            cmd = conn._cmdTempUpdateShort;
                        }
                        else
                        {
                            cmd = conn._cmdTempUpdateShortNullLong;
                        }
                    }
                    else
                    {
                        if (item.streamLength <= ITEM_SHORT_LENGTH)
                        {
                            cmd = conn._cmdTempUpdateLongNullShort;
                        }
                        else
                        {
                            cmd = conn._cmdTempUpdateLong;
                        }
                    }
                }
                else
                {
                    if (length <= ITEM_SHORT_LENGTH)
                    {
                        cmd = conn._cmdTempInsertShort;
                    }
                    else
                    {
                        cmd = conn._cmdTempInsertLong;
                    }
                }

                cmd.Parameters[0].Value = id + s_appSuffix;
                cmd.Parameters[1].Size  = length;
                cmd.Parameters[1].Value = buf;
                cmd.Parameters[2].Value = item.timeout;
                if (inStorage)
                {
                    cmd.Parameters[3].Value = item.lockCookie;
                }

                try {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e) {
                    SqlException sqlExpt = e as SqlException;
                    if (sqlExpt != null &&
                        sqlExpt.Number == SQL_ERROR_PRIMARY_KEY_VIOLATION &&
                        !inStorage)
                    {
                        Debug.Trace("SessionStateClientSet",
                                    "Insert failed because of primary key violation; just leave gracefully; id=" + id);

                        // It's possible that two threads (from the same session) are creating the session
                        // state, both failed to get it first, and now both tried to insert it.
                        // One thread may lose with a Primary Key Violation error. If so, that thread will
                        // just lose and exit gracefully.
                    }
                    else
                    {
                        throw new HttpException(
                                  HttpRuntime.FormatResourceString(SR.Cant_connect_sql_session_database),
                                  e);
                    }
                }
            }
            catch {
                conn.Dispose();
                throw;
            }

            ReuseConnection(ref conn, usePooling);
        }