# sql: transaction has already been committed or rolled back

- **ID:** `go/database-sql-tx-committed`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to execute a query on a transaction that has already been committed or rolled back.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.21 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   tx, err := db.BeginTx(ctx, nil)
if err != nil {
    // handle
}
// defer tx.Rollback() to ensure cleanup
if err := tx.Commit(); err != nil {
    // handle
}
   ```
2. **** (70% success)
   ```
   Check the transaction state before executing queries.
   ```

## Dead Ends

- **** — Once a transaction is done, it cannot be reused. (90% fail)
- **** — Commit() can only be called once. (80% fail)
