| title | sp_bindsession (Transact-SQL) | Microsoft Docs | ||
|---|---|---|---|
| ms.custom | |||
| ms.date | 03/14/2017 | ||
| ms.prod | sql-non-specified | ||
| ms.reviewer | |||
| ms.suite | |||
| ms.technology |
|
||
| ms.tgt_pltfrm | |||
| ms.topic | language-reference | ||
| f1_keywords |
|
||
| dev_langs |
|
||
| helpviewer_keywords |
|
||
| ms.assetid | 1436fe21-ad00-4a98-aca1-1451a5e571d2 | ||
| caps.latest.revision | 38 | ||
| author | BYHAM | ||
| ms.author | rickbyh | ||
| manager | jhubbard |
[!INCLUDEtsql-appliesto-ss2008-xxxx-xxxx-xxx_md]
Binds or unbinds a session to other sessions in the same instance of the [!INCLUDEssNoVersion] [!INCLUDEssDE]. Binding sessions allows two or more sessions to participate in the same transaction and share locks until a ROLLBACK TRANSACTION or COMMIT TRANSACTION is issued.
Important
[!INCLUDEssNoteDepFutureAvoid] Use Multiple Active Results Sets (MARS) or distributed transactions instead. For more information, see Using Multiple Active Result Sets (MARS).
| Applies to: [!INCLUDEssNoVersion] ([!INCLUDEssKatmai] through current version). |
Transact-SQL Syntax Conventions
sp_bindsession { 'bind_token' | NULL }
' bind_token '
Is the token that identifies the transaction originally obtained by using sp_getbindtoken or the Open Data Services srv_getbindtoken function. bind_tokenis varchar(255).
0 (success) or 1 (failure)
Two sessions that are bound share only a transaction and locks. Each session retains its own isolation level, and setting a new isolation level on one session does not affect the isolation level of the other session. Each session remains identified by its security account and can only access the database resources to which the account has been granted permission.
sp_bindsession uses a bind token to bind two or more existing client sessions. These client sessions must be on the same instance of the [!INCLUDEssDE] from which the binding token was obtained. A session is a client executing a command. Bound database sessions share a transaction and lock space.
A bind token obtained from one instance of the [!INCLUDEssDE] cannot be used for a client session connected to another instance, even for DTC transactions. A bind token is valid only locally inside each instance and cannot be shared across multiple instances. To bind client sessions on another instance of the [!INCLUDEssDE], you must obtain a different bind token by executing sp_getbindtoken.
sp_bindsession will fail with an error if it uses a token that is not active.
Unbind from a session either by using sp_bindsession without specifying bind_token or by passing NULL in bind_token.
Requires membership in the public role.
The following example binds the specified bind token to the current session.
Note
The bind token shown in the example was obtained by executing sp_getbindtoken before executing sp_bindsession.
USE master;
GO
EXEC sp_bindsession 'BP9---5---->KB?-V'<>1E:H-7U-]ANZ';
GO
sp_getbindtoken (Transact-SQL)
srv_getbindtoken (Extended Stored Procedure API)
System Stored Procedures (Transact-SQL)