sp_getbindtoken (T-SQL)

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.

Syntax

sp_getbindtoken [@out_token =] 'return_value' OUTPUT [, @for_xp_flag]

Arguments
[@out_token =] 'return_value'
Is the token to use to share a transaction context. return_value is varchar(255), with no default.
@for_xp_flag
Is a constant. If equal to 1, a bind token is created that can be passed to an extended stored procedure to call back into the server.
Return Code Values

None

Result Sets

None

Remarks

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.


Permissions

Only the owner of the bind token can retrieve that particular bind token.

Examples
A. Obtain a 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.


B. Use the @for_xp_flag parameter

    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

      

    See Also
    sp_bindsession System Stored Procedures
    srv_getbindtoken  

      


    (c) 1988-98 Microsoft Corporation. All Rights Reserved.