Skip to main content

SQL Server Source

Read from a Microsoft SQL Server database as a drt sync source (via pymssql).

Profile (~/.drt/profiles.yml)​

mssql_prod:
type: sqlserver
host: sql.example.com
port: 1433
database: analytics
user: drt_reader
password_env: MSSQL_PASSWORD
schema: dbo

Configuration​

FieldTypeDefaultDescription
type"sqlserver"—Required
hoststring—Server hostname
portint1433SQL Server default port
databasestring—Database name
userstring—Username
password_envstring | nullnullEnv var holding the password (preferred)
passwordstring | nullnullInline password (not recommended)
schemastringdboDefault schema for unqualified table names

Notes​

  • Requires the extra: pip install drt-core[sqlserver] (pulls in pymssql).
  • Prefer password_env over an inline password.
  • Each sync's model SQL runs against the database; qualify tables as schema.table or rely on the profile's schema.

Retry on transient extract failures (#766)​

Opening the connection and running the query are retried automatically (3 attempts, exponential backoff from 1s, capped at 60s). No configuration — it is always on.

Retried (pymssql):

  • OperationalError — connection refused, the server restarting, or an Azure SQL failover moving the database between replicas.
  • InterfaceError — the driver's connection object went bad.

Not retried: ProgrammingError (bad SQL, missing table), DataError, IntegrityError, NotSupportedError. pymssql follows PEP 249 exactly, so these are siblings of OperationalError under DatabaseError — matching the two specific classes rather than the base is what keeps a SQL typo from being retried three times.

⚠️ Scope: connection + query execution + fetching the result set only. A failure after the first row has been yielded is not retried and fails the sync — those rows are already loaded into the destination and cannot be un-sent. See API_REFERENCE for the full rationale.

References​

Streaming extraction (#765)​

Rows are read in fetch_size batches rather than materialised whole, so peak memory tracks the batch instead of the result set — roughly a 4× reduction on a 300k-row extract. Measured figures for every source are collected in Extraction memory.

fetch_size: 10000 # rows per batch (default: 10000)

Memory scales with fetch_size x row width, not row count — lower it for very wide rows, not for big tables.