Skip to content

Results and error codes

connect

driver.connect(params) returns a decltype(driver)::e_driver_error_code:

Value Meaning
success Connected and logged in
connection_failed Every connection attempt failed, TLS failures included
login_failed Connected, but the server refused the login. The reason went to the info callback
connection_param_server_name_empty server_name is empty
connection_param_packet_size_invalid packet_size is not between 512 and 32767
connection_param_retry_invalid conn_retry_count or conn_retry_delay_ms is above 65535
busy Called from one of the driver's callbacks, while a request is running. Nothing was done

connect blocks until it succeeds or the last attempt fails. See Connection parameters for the worst case.

execute_query

execute_query returns a query result. It converts to true when the query succeeded.

Member Type Meaning
affected_rows uint32_t Rows affected or returned by the last statement that reports a count
request_too_large bool The query doesn't fit into the network buffer. Nothing was sent
network_error bool Sending or receiving failed, or SQL Server ended the session with a fatal error (severity 20 or above, e.g. the session was killed), and the connection is closed. The query may or may not have run. Also set when the driver isn't logged in (e.g. connect failed). Reconnect
response_too_large bool A row, the column list or a message of the response is larger than the network buffer. The query ran. The connection is closed, so network_error is set too. Reconnect
response_error bool The response couldn't be processed (unsupported column type, out of memory). The result set may be incomplete. The connection stays usable
busy bool Called from one of the driver's callbacks (e.g. the row callback), while another request is running. Nothing was sent, and the running request isn't affected
status tds_done_token::status_type The status of SQL Server's last DONE token

When the result is false and none of the flags is set, SQL Server reported an error; its message went to the info callback. The connection stays usable.

execute_rpc

execute_rpc returns a tdsl::expected<tdsl::uint32_t, e_rpc_error_code>. When it converts to true, get() is the number of rows affected or returned. Otherwise error() is a tdsl::detail::e_rpc_error_code:

Value Meaning
invalid_mode The mode isn't supported. Only tdsl::rpc_mode::executesql is
request_too_large The request doesn't fit into the network buffer. Nothing was sent
invalid_response The response couldn't be processed completely
server_error SQL Server reported an error. Its message went to the info callback. Not reported for some errors inside stored procedures; see Call a stored procedure
network_error Sending or receiving failed, or SQL Server ended the session with a fatal error (severity 20 or above), and the connection is closed; or the driver isn't logged in. Reconnect
response_too_large A row, the column list or a message of the response is larger than the network buffer. The request ran. The connection is closed. Reconnect
invalid_parameter A parameter has an unsupported type or an invalid size. Nothing was sent
busy Called from one of the driver's callbacks, while another request is running. Nothing was sent

The driver can't be called from its own callbacks (row, info, column names): the running request uses the connection and the network buffer. Store what you need in the callback, and send the next request after the running one returns.

Info callback

The info callback receives a tdsl::tds_info_token for each message from SQL Server:

Member Meaning
number SQL Server's message number, e.g. 18456 (login failed), 208 (invalid object name)
state The error state
class_ The severity. Above 10 is an error; 20 and above is fatal: SQL Server ends the session and closes the connection
line_number Line of the batch or procedure the message is about
msgtext The message, as tdsl::u16le_view (UTF-16)
server_name The server's name, UTF-16
proc_name The stored procedure's name, if any, UTF-16
is_error(), is_info() Whether the severity makes it an error
is_fatal() Severity 20 or above: the session ends. The request then reports a network error

Backends

connect reports every network failure as connection_failed. The backend's own error code tells more. To see it, call the backend's do_connect yourself while you investigate:

auto r = driver.network().do_connect(tdsl::string_view{"db.example"}, 1433);
if (not r) {
    printf("do_connect failed: %d\n", r.error());
}

BSD sockets

tdsl::net::tdsl_netimpl_socket::e_socket_error:

Value Code Meaning
host_too_long -1 The host name is longer than 255 characters
resolve_failed -2 The host name couldn't be resolved
connection_failed -3 The TCP connection couldn't be established
disconnected -4 The server closed the connection
timeout -5 No data arrived within the I/O timeout
io_error -6 A socket call failed
not_enough_capacity -7 The data doesn't fit into the network buffer
not_connected -8 Not connected

TLS backends

ESP-IDF (tdsl::net::tdsl_netimpl_esp_tls::e_socket_error) has the codes of the BSD sockets backend, plus:

Value Code Meaning
tls_handshake_failed -9 The TLS handshake failed, e.g. the server doesn't support strict mode
tls_verify_failed -10 The server's certificate was rejected: unknown CA, wrong host name, expired... connect doesn't retry
tls_setup_failed -11 The TLS settings couldn't be applied, e.g. no CA given, or it can't be parsed. connect doesn't retry
packet_too_large -12 A TDS packet doesn't fit into one TLS record. Nothing was sent
tls_init_failed -13 The TLS session couldn't be set up, e.g. not enough heap. Retrying may help
not_contiguous -14 Internal: the packet header wasn't in front of its data. Nothing was sent

Boost.ASIO (tdsl::net::tdsl_netimpl_asio_tls::e_connect_error):

Value Code Meaning
resolve_failed -2 The host name couldn't be resolved
connection_failed -3 The TCP connection couldn't be established
tls_handshake_failed -4 The TLS handshake failed
tls_verify_failed -5 The server's certificate was rejected
tls_setup_failed -6 The TLS settings couldn't be applied, e.g. the CA file can't be read

Arduino

do_send of tdsl::net::tdsl_netimpl_arduino returns an e_send_error:

Value Code Meaning
write_failed -1 Writing failed. The connection is closed
packet_too_large -2 A TDS packet is larger than the TLS client's record (see set_tls_client). Nothing was sent; the connection stays usable
not_contiguous -3 Internal: the packet header wasn't in front of its data. Nothing was sent