DEV Community

Mads Hansen
Mads Hansen

Posted on

A SQL Server login is not a complete execution contract

The same SQL Server query text can mean something different on the next pooled connection.

Language and DATEFORMAT change date parsing.

DATEFIRST changes week calculations.

ANSI settings change errors and expression behavior.

Default database, schema, isolation, and leftover transaction state change the execution boundary.

So a SQL Server login is not a complete contract.

Before ChatGPT can use a connection, establish and verify a versioned baseline:

  • database, schema, role, and approved objects
  • language, date format, first day of week, and reporting cutoff
  • required ANSI and error settings
  • isolation, lock timeout, command timeout, and cancellation
  • trusted user/tenant context
  • read-only scope and result limits

Use typed date parameters and schema-qualified objects. Reset or discard dirty pooled sessions. Record a normalized session fingerprint with the operation trace.

Then test new versus reused connections, changed login defaults, weekly boundaries, missing ANSI options, same-named objects in another schema, leftover transactions, locks, timeouts, and cancellation.

If the effective session differs from the reviewed contract, fail closed. A plausible answer under unknown semantics is not a successful database connection.

Full guide: Connect SQL Server to ChatGPT with a deterministic session contract

Top comments (0)