Jaa


sp_bindsession (Transact-SQL)

Binds or unbinds a session to other sessions in the same instance of the SQL Server Database Engine. 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.

For more information about bound sessions, see Using Bound Sessions.

Important

This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use Multiple Active Results Sets (MARS) or distributed transactions instead. For more information, see Using Multiple Active Result Sets (MARS) or Distributed Transactions (Database Engine).

Topic link iconTransact-SQL Syntax Conventions

Syntax

sp_bindsession { 'bind_token' | NULL }

Arguments

  • '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).

Return Code Values

0 (success) or 1 (failure)

Remarks

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 Database Engine 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 Database Engine 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 Database Engine, 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.

Permissions

Requires membership in the public role.

Examples

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

See Also

Reference

sp_getbindtoken (Transact-SQL)
System Stored Procedures (Transact-SQL)

Other Resources

Using Bound Sessions
srv_getbindtoken (Extended Stored Procedure API)

Help and Information

Getting SQL Server 2005 Assistance