# sql: database is closed

- **ID:** `go/database-sql-max-open-connections`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to use a database handle after calling db.Close(), resulting in an error.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.15 | active | — | — |
| 1.19 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Use a sync.Once to close the database only once: var closeOnce sync.Once; closeOnce.Do(func() { db.Close() })
   ```
2. **** (70% success)
   ```
   Check if db is nil before using: if db == nil { return errors.New("db is closed") }
   ```

## Dead Ends

- **** — May be impossible if the database is down or configuration changed. (50% fail)
- **** — All subsequent queries will fail, causing application malfunction. (90% fail)
