sp_getbindtoken (version 6.5)

Creates a bound connection context and returns a unique identifier for the created context. This unique identifier is referred to as a bind token. This system stored procedure returns a string representation to use as a token for a shared transaction between two clients.

Syntax

sp_getbindtoken return_value OUTPUT [, @for_xp_flag]

where

return_value OUTPUT
Is the token to use to share a transaction context. This parameter can have a maximum of 255 characters and must have a varchar datatype.
@for_xp_flag
Specifies a literal constant. If equal to 1, creates a bind token that can be passed to an extended stored procedure to call back into the server.

Remarks

The bind token can be used with sp_bindsession to bind new sessions to the same transaction context. Sessions on one 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 will run correctly.

If a literal constant is not used for the @for_xp_flag parameter, you will receive the following error message:

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.

For more information about sharing a transaction context and binding connections, see sp_bindsession.

For more information about the srv_getbindtoken Open Data Services API, see What's New for Open Data Services later in this document.

Examples

A.    Obtain 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 results set:

Token
----------------------------------------------------------
\0]---5^PJK51bP<1F<-7U-]ANZ
  

Note Your bind token name will differ from the results displayed above.

B.    Use @for_xp_flag Parameter

This example specifies a literal 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

For more information about binding connections, see sp_bindsession, earlier in this document.