Creates a bound connection context and returns a unique identifier for the created context. This unique identifier is referred to as a bind token. sp_getbindtoken returns a string representation to use as a token for a shared transaction between two clients.
sp_getbindtoken [@out_token =] 'return_value' OUTPUT [, @for_xp_flag]
None
None
The bind token can be used with sp_bindsession to bind new sessions to the same transaction context. Sessions on one computer running Microsoft® SQL Server™ that are bound to the same transaction context share a single-transaction lock space during each session.
To obtain and pass a bind token, you must run sp_getbindtoken prior to executing sp_bindsession for sharing the same lock space. If you obtain a bind token, sp_bindsession runs correctly.
If a constant is not used for @for_xp_flag, this error message is returned:
Msg 214, Level 16, State 1, Server <server_name>, Procedure
<procedure_name>, Line 5
Cannot convert parameter @for_xp_flag to type constant expected by
procedure.
Note It is recommended that you use the srv_getbindtoken Open Data Services API to obtain a bind token to be used from an extended stored procedure.
Only the owner of the bind token can retrieve that particular bind token.
This example obtains a bind token and displays the bind token name.
DECLARE @bind_token varchar(255)
EXECUTE sp_getbindtoken @bind_token OUTPUT
SELECT @bind_token AS Token
This is the result set:
Token
----------------------------------------------------------
\0]---5^PJK51bP<1F<-7U-]ANZ
Note Your bind token name will differ from the results displayed.
This example specifies a constant to use for calling back to the server.
DECLARE @bind_token varchar(255)
EXECUTE sp_getbindtoken @bind_token OUTPUT, 1
SELECT @bind_token AS Token
sp_bindsession | System Stored Procedures |
srv_getbindtoken |