Skip to content

Troubleshoot

Start by registering an info callback: most failures come with a message from SQL Server that names the problem.

Connecting

connect returns connection_failed

The TCP connection couldn't be established.

  • Check the server address and the port (1433 by default).
  • From a board, use your computer's IP address, not localhost.
  • Check that the computer's firewall lets port 1433 in.
  • Check that SQL Server accepts TCP connections. In SQL Server Configuration Manager (Windows), TCP/IP must be enabled.

connect returns login_failed

The server was reached, but refused the login.

  • Error 18456 (Login failed for user ...) in the info callback: the user name or password is wrong, or the user can't use SQL Server authentication. Windows authentication isn't supported.
  • The user name and password are right: the server may require encryption, and it refuses unencrypted logins. Connect with TLS.

connect returns connection_param_*

A connection parameter is invalid:

  • connection_param_server_name_empty: server_name isn't set.
  • connection_param_packet_size_invalid: packet_size isn't between 512 and 32767.
  • connection_param_retry_invalid: conn_retry_count or conn_retry_delay_ms is above 65535.

A TLS connection fails

TLS failures make connect return connection_failed.

  • Check the SQL Server error log. Error 17821 means the server has no certificate configured for strict connections.
  • Otherwise the certificate was probably rejected: the CA you gave the device must be the one that signed the server's certificate, and the host name (or IP address) you connect to must be in the certificate.
  • On boards, the clock must be set before connecting, or every certificate looks not yet valid.
  • The backend's do_connect result names the reason; see TLS error codes.

Queries

A number reads as zero

The type given to as<T>() is wider than the column: a smallint column reads as zero with as<tdsl::int32_t>(). Use as<tdsl::int16_t>(). See Data types.

A string is garbled, or has a \0 after every character

The column is nchar or nvarchar, which are UTF-16. Read it with as<tdsl::u16le_view>() instead of as<tdsl::char_view>().

A date reads as a string

That's expected: SQL Server sends date, time, datetime2 and datetimeoffset to tdslite as nvarchar. See Data types.

The result reports request_too_large

The query doesn't fit into the network buffer. Shorten it, or enlarge the buffer; see Limits.

The result reports network_error while reading rows

The connection was lost, the response took longer than the receive timeout, or, with response_too_large set too, a row, the column list or a message (e.g. from PRINT) is larger than the network buffer. In each case tdslite closes the connection, so that the rest of the response is never read as the next query's result. Reconnect with driver.connect(...). For response_too_large, enlarge the buffer, select shorter values or fewer columns, or shorten the message: running the query again ends the same way. For a slow query on an Arduino-core board, raise the timeout with driver.network().set_receive_timeout(ms).

The result reports response_error

The response couldn't be processed: it has a column of an unsupported type (e.g. sql_variant), or there wasn't enough memory.

Error 3989 after BEGIN TRAN on a TLS connection

On TLS connections, a transaction must start and end within one query. See Connect with TLS.

Hardware

My Ethernet library isn't supported

Most Ethernet libraries implement the EthernetClient interface and work with tdsl::arduino_driver directly. If yours doesn't, you can:

  1. write a wrapper class for it, see Write a network backend;
  2. ask the library's author to implement a compatible interface;
  3. open an issue to suggest support in tdslite, if the library is widely used.

Still stuck?

Open an issue with your board, backend, SQL Server version and what the info callback printed.