SQL Server packets

All communication between SQL Server clients and servers is done through discrete packets. Some packet types can be sent by the client to the server, others by the server to the client, and a few can be sent from either side.

For full details, consult the SQL Server documentation.

An idiosyncrasy of SQL Server is that it distinguishes between packets and tokens. Generally speaking, clients send packets to the server, and the server responds with tokens (that's not really true but it's a simple way to think about it).

Both packets and tokens share the following properties:

  • byte typeCode: a numeric representation of the type of packet or token. The Microsoft documentation for tokens is here, and here for packets.

  • string packetType: a string representation of the type of packet or token. This will return the type of the packet as defined here, e.g. a Row token will return "Row".

  • remove(): marks the packet/token as "deleted" -- Gallium Data will not forward it to its destination.

  • toString(): returns a string representation of the packet/token.


Packets (but not tokens) also have the following properties:

  • boolean statusEndOfMessage: if set, this is the last message of a stream.

  • boolean statusIgnoreThisEvent: ignore this event (used to abort operations).

  • boolean statusResetConnection: reset this connection.

  • boolean statusResetConnectionSkipTran: reset this connection but do not reset the transaction state.

Full documentation for these status flags is available here.

  • short spid: the process ID on the server, can be set to 0 in packets sent from the client.

  • byte packetId: in a multi-packet stream, the number of the packet. This is handled automatically by Gallium Data and should not normally be changed.

  • byte window: no used, should always be 0.


The packet/token types most commonly used in user logic are: SQLBatch, RPC, Row and NBCRow.

Request packets

These packet types can only be sent from the client to the server.

Attention: sent to interrupt a request.

Login7: contains the login information.

RPC: used to call a stored procedure.

SQLBatch: used to execute one or more SQL statement.

Response tokens

These token types can only be sent from the server to the client.

ColInfo: sent when in browse mode.

ColMetadata: the metadata for a result set.

Done: sent to mark the end of a response.

EnvChange: sent to signal a change in the environment.

Error: sent when there was error processing a SQL statement or stored procedure call.

Info: sent to inform the client of something.

NBCRow: exactly the same as Row, but with better handling of null values.

Order: sent to indicate by which columns the data is ordered.

Row: contains a row of data.

SSPIToken: may be used as part of the authentication process.

TabName: contains the table name in browse mode.

Duplex packets

These packets can be sent either from the client to the server, or from the server to the client.

PreLogin: exchanged during the initial handshake before login.

SSPI: may be used as part of the authentication process.