Skip to main content
Version: Next

Troubleshooting

Connection Refused​

Error: Failed to connect to SQL Server: Connection refused

Solutions:

  • Verify SQL Server hostname and port are correct
  • Check firewall allows TCP connections on port 1433
  • Ensure SQL Server is configured for TCP/IP connections (SQL Server Configuration Manager)
  • Test connectivity: telnet hostname 1433

Login Failed​

Error: Login failed for user 'username'

Solutions:

  • Verify username and password are correct
  • Ensure SQL Server authentication mode is enabled (not Windows-only)
  • Check user has access to the specified database
  • Verify user account is not locked or disabled

TLS Required​

Error: Server requires encryption but TLS is not available

Solutions:

  • Enable encryption in connection: use_encrypt true or Encrypt=yes
  • Ensure extension was built with OpenSSL (default for vcpkg builds)

Certificate Verification Failed​

TLS handshake failed: certificate verification failed for localhost: self-signed certificate. Set TrustServerCertificate=yes to accept this server's certificate without verification, or HostNameInCertificate=<name> if the certificate is valid but issued for a different name

The server's certificate could not be verified (spec 074): the chain does not lead to a root in the platform trust store (self-signed certificate, unable to get local issuer certificate), or its subject is not the host you connected to (hostname mismatch).

Solutions:

  • A self-signed certificate you know (docker, an on-prem instance with none installed): add TrustServerCertificate=yes / trust_server_certificate true
  • The certificate is valid but you connect through a tunnel, an IP or an alias: add HostNameInCertificate=<the name in the certificate>
  • unable to get local issuer certificate on a minimal Linux image: install ca-certificates, or point SSL_CERT_FILE at a bundle; a private CA goes into the platform store or SSL_CERT_FILE

TLS Handshake Failed​

Error: TLS handshake failed

Solutions:

  • Verify server certificate is valid
  • Check TLS version compatibility (TLS 1.2+ required)
  • Set MSSQL_DEBUG=1 for detailed TLS debugging output
  • Verify server hostname matches certificate

Type Conversion Error​

Error: Unsupported SQL Server type 'UDT' (0xF0) for column 'col_name'

Solutions:

  • Check the Type Mapping section for supported types
  • Cast unsupported columns to supported types in your query
  • Exclude unsupported columns from SELECT

DuckDB UI: "Expected field id 65535 but got 103"​

Error: Expected field id 65535 but got 103 (offset=50)

Raised by the DuckDB UI extension (CALL start_ui_server()) — and only there — when a result contains a column read from an attached table whose type is MSSQL_VARCHAR(n) / MSSQL_NVARCHAR(n). The UI serializes the result's column types for the browser, and its reader does not know the extension_info block (field 103) that DuckDB writes for an extension type with modifiers; the CLI, Python and JDBC clients never serialize result types, so the same query runs there. Tracked as issue #297.

Solutions:

  • Report plain VARCHAR for attached string columns, then drop the entries the catalog has already loaded with the native type:

    SET mssql_catalog_native_types = false;
    SELECT mssql_invalidate_cache('mydb');

    Or for one catalog only, at ATTACH: ATTACH '…' AS mydb (TYPE mssql, native_types false).

    The cost is what the setting's name says: DESCRIBE shows VARCHAR instead of the declared length and collation, and a CTAS or COPY back to SQL Server no longer inherits them (Catalog-Reported String Types).

  • Per query, CAST(col AS VARCHAR) yields a plain VARCHAR as well.

"Invalid column name" / "Invalid object name" after a change on the server​

SQL Server error [207, severity 16]: Invalid column name 'FieldName'. (table db.dbo.MyTable: its columns
changed on the server since they were loaded; its cached metadata is dropped now, run the statement again)

The catalog keeps a table's columns from its first read until it is invalidated (mssql_catalog_cache_ttl is 0 by default), and a long-lived DuckDB process -- the DuckDB UI, a server -- keeps them for days. When another client drops or renames a column, or the table, the next read of it fails once, as above, and the table's cached entry is dropped: run the statement again.

A view that names a column dropped from its table no longer compiles on the server; reloading its columns would not help, so its error says "fix the view there, then mssql_invalidate_cache(…)".

A statement sent to the server whole (an aggregate, a join, an ORDER BY …, remote pushdown) can read several tables, and it fails until the catalog is invalidated. To pick up changes made outside DuckDB:

SELECT mssql_invalidate_cache('db', 'dbo', 'MyTable'); -- one table
SELECT mssql_invalidate_cache('db'); -- the whole catalog
SET mssql_catalog_cache_ttl = 3600; -- or: reload metadata older than an hour

Slow Query Performance​

Solutions:

  • Verify filter pushdown is working (check query plan)
  • Reduce result set size with LIMIT or WHERE clauses
  • Increase connection pool size for concurrent queries
  • Check network latency to SQL Server
  • Consider using mssql_scan() for complex queries with explicit SQL

Limitations​

Unsupported Features​

  • UPDATE / DELETE … RETURNING on Fabric Warehouse and Azure Synapse: refused by name; both lack the OUTPUT … INTO the rows are read back through. On SQL Server and Azure SQL they work. See DML.
  • UPDATE / DELETE on a table with no usable key, when the statement cannot go to the server whole: such a table is keyed by every column, which needs the server to select the same rows as DuckDB, and is refused by name when it cannot (a WHERE that runs in DuckDB, a volatile function, UPDATE … FROM). A primary key or a unique index lifts it. See DML.
  • A SET of a key column goes only when the UPDATE goes to the server whole (mssql_dml_pushdown); the row paths select rows by that key.
  • MERGE INTO an MSSQL table runs on the server or is refused: more WHEN clauses than T-SQL takes, ERROR, an INSERT naming the identity column, RETURNING, a subquery, an expression over the target T-SQL cannot write (a string function, unary minus), and any MERGE with DuckDB's optimizer off are refused by name. SET x = DEFAULT writes NULL. A source value compared with a temporal column of the target is rounded to that column's precision first, as the server compares. See MERGE INTO.
  • UPDATE / DELETE / MERGE on Azure Synapse: refused; its keys are NOT ENFORCED and its MERGE is in preview.
  • Keytab / raw Kerberos credentials on macOS: macOS's GSS.framework lacks MIT extensions for gss_acquire_cred_from keytab and raw-password paths. macOS supports credential-cache mode only (via kinit); keytab and raw-credentials modes are Linux-only. See Kerberos.md for the WSL2 / Docker testing path.
  • Multiple result sets: Only one result-producing statement per mssql_scan() batch is allowed
  • Stored Procedures with Output Parameters: Use mssql_scan() for stored procedures
  • rowid for views and tables without a usable key: rowid is the primary key, else a usable unique index (not filtered, not disabled, NOT NULL columns that a literal matches); a view or a table with neither has no rowid

VARCHAR Encoding​

A CHAR or VARCHAR column under a code-page collation (e.g. Latin1_General_CI_AS) holds bytes in that code page, while DuckDB VARCHAR is UTF-8. How it reaches DuckDB depends on the page:

Column, read through the catalogSent asConverted by
CHAR, VARCHAR, VARCHAR(MAX) on a single-byte page (1250-1258, 874, 437, 850)itself: one byte a characterthe client
The same on a double-byte page (932, 936, 949, 950)NVARCHAR(n), NCHAR(n), or NVARCHAR(MAX) past 4000the server
TEXT, any pageNVARCHAR(MAX)the server
A collation with a UTF-8 code page (..._UTF8)itselfnothing: it is UTF-8

The client reads a byte exactly as the server's CAST would: the tables come from a SQL Server, and include the bytes a code page leaves undefined. A CHAR(n) arrives without its padding either way.

Settings:

SettingTypeDefaultDescription
mssql_client_transcodeBOOLEANtrueRead code-page text as bytes and convert it on the client; read at ATTACH. false makes the server convert every column, and leaves a raw mssql_scan with the column's bytes (below)
mssql_convert_varchar_maxBOOLEANtrueConvert a declared VARCHAR(MAX) on the server, where the server converts. false on a double-byte page drops that cast, and the client converts the column. No effect on a single-byte page, read as itself either way

ATTACH ... (TYPE mssql, client_transcode false) sets it for one catalog.

When code-page bytes reach you unconverted​

A raw mssql_scan() returns correct UTF-8 for every code page, and a catalog read for every column. Two cases hand a CHAR / VARCHAR / TEXT column's bytes over as they are:

  • client_transcode is off for the catalog (mssql_client_transcode = false, or the ATTACH option), on a raw mssql_scan(), or on a catalog read of a declared VARCHAR(MAX) with mssql_convert_varchar_max = false;
  • the collation is newer than this build's tables, on a raw mssql_scan().

Symptom. A string looks right in the output but behaves as if it were truncated:

SELECT upper(name) FROM mssql_scan('db', 'SELECT name FROM dbo.t');
-- 'naïve' comes back as 'NA'

Cause. ï in CP1252 is the single byte 0xEF, which UTF-8 reads as the start of a three-byte sequence, so upper() consumes the two bytes after it. DuckDB VARCHAR is UTF-8 by contract, and these values are not validated on the way in: that would cost every scan a second pass over bytes it has already copied.

Both cases log one WARNING per column per query into duckdb_logs (mssql_warn_non_utf8_collation turns it off).

Fix. Attach with client_transcode true, the default. Or CAST in the query, to NVARCHAR(MAX) and not NVARCHAR(n): SQL Server does not raise on a narrowing character CAST, so a fixed width silently truncates:

SELECT * FROM mssql_scan('db',
'SELECT id, CAST(name AS NVARCHAR(MAX)) AS name FROM dbo.customers');

To get the stored bytes on purpose, CAST(name AS VARBINARY(MAX)) in the T-SQL, on any setting.

A warning that a column "is in the catalog under collation"​

The column's collation changed on the server after the catalog loaded it. The values are read correctly, by the collation the server sent, but DESCRIBE shows the old one. Run mssql_invalidate_cache(). For a view, sp_refreshview first: its sys.columns row stays old until then.

Unicode Transcoding (simdutf)​

DuckDB strings are UTF-8 internally; the TDS wire protocol carries character data as UTF-16LE. Every NVARCHAR / NCHAR / NTEXT / XML value the extension reads from SQL Server is decoded from UTF-16LE to UTF-8 before being handed to DuckDB, and every string the extension sends back (LOGIN7 fields, INSERT/UPDATE parameters, T-SQL identifiers in BCP metadata, etc.) is encoded the other direction. On a SELECT that returns millions of rows, that's a lot of bytes — and the codec sits squarely in the hot path.

The extension uses simdutf for that conversion. simdutf is a SIMD-accelerated Unicode validation and transcoding library by Daniel Lemire and contributors; on modern x86_64 (AVX-512 / AVX2 / SSE) and ARM64 (NEON / SVE) cores it typically transcodes UTF-8 ↔ UTF-16 at 2–5 GB/s, an order of magnitude faster than the hand-rolled byte-at-a-time loops it replaced. The library is dual-licensed MIT / Apache-2.0; the extension links it statically under the MIT terms.

Where simdutf is called (src/tds/encoding/utf16.cpp):

Directionsimdutf entry pointsUsed by
UTF-8 → UTF-16LE (encode)simdutf::validate_utf8, simdutf::utf16_length_from_utf8, simdutf::convert_valid_utf8_to_utf16leLOGIN7 client/host/app/server/library/language/database/SSPI fields; T-SQL batches built by INSERT/UPDATE/DELETE; BCP column metadata; identifier quoting
UTF-16LE → UTF-8 (decode)simdutf::validate_utf16le, simdutf::utf8_length_from_utf16le, simdutf::convert_valid_utf16le_to_utf8NVARCHAR / NCHAR / NTEXT / SQL_VARIANT-string / XML column results; ENVCHANGE token payloads; ERROR/INFO token messages

The codec validates the input first and falls back to a slower scalar implementation only when input is malformed — so well-formed UTF-8/UTF-16 (the overwhelming majority of real traffic) hits the SIMD fast path every time. There is a microbenchmark (make bench-utf16) and an end-to-end before/after benchmark (test/bench/bench_codec_e2e.sh) recorded in bench_results.md.

Dependency surface: simdutf is pulled in statically via vcpkg.json ("simdutf" dependency, version resolved from the builtin-baseline pin). Release binaries embed it; downstream builds that don't use vcpkg need to provide simdutfConfig.cmake some other way (e.g., the test/kerberos/test-client Docker image builds it from upstream at a pinned tag).

Known Issues​

  • Catalog scans read a user CLR type through a cast to NVARCHAR(MAX) (its ToString() text); sql_variant, hierarchyid, geometry and geography are decoded on the client (see Reading / Types). A raw mssql_scan() reads a user CLR type as a BLOB of its bytes
  • A serverless Azure SQL database that is resuming answers a login with error 40613 ("not available yet ... retry shortly") until it is up, typically 20 to 60 s. The extension tries the login again, as it does for 40197, 40143, 40501, 49918 and 42109 (a Synapse / Fabric pool warming up; not 42108, a paused pool, which nothing resumes while the login waits) (#481): the pause starts at 1 s and doubles to 10 s, within mssql_connection_timeout (for the ATTACH, mssql_attach_validation_timeout when set), each attempt an INFO line in duckdb_logs, and Ctrl-C ends it. An extra parallel bulk-load writer makes one attempt; the connections min_connections opens at ATTACH retry but cannot be interrupted. The 30 s default can be short for a resume: raise the timeout (SET mssql_connection_timeout = 90) if the ATTACH still fails with tried N time(s).
  • Under client_transcode false, raw mssql_scan() returns non-Unicode CHAR/VARCHAR/TEXT bytes in the column's code page without transcoding them; see When code-page bytes reach you unconverted
  • The DuckDB UI cannot render a result with an MSSQL_VARCHAR(n) / MSSQL_NVARCHAR(n) column (Expected field id 65535 but got 103) — set mssql_catalog_native_types = false and invalidate the cache. See DuckDB UI
  • XML columns in INSERT/UPDATE are limited to 4096 bytes per value — use COPY TO with BCP protocol for larger documents
  • Very large DECIMAL values may lose precision at extreme scales
  • Connection pool statistics reset when all connections close
  • Microsoft Fabric Warehouse has no nvarchar type at all, and no datetimeoffset — so a TIMESTAMP WITH TIME ZONE column cannot be created there. varchar(max) is supported. See AZURE.md
  • A #temp table cannot be a BCP target on Microsoft Fabric: the load fails inside Fabric with an I/O error against a parquet file. Load into a permanent table