srv_getbindtoken (Extended Stored Procedure API)
This feature will be removed in a future version of Microsoft SQL Server. Do not use this feature in new development work, and modify applications that currently use this feature as soon as possible. Use CLR integration instead.
Obtains a bind token of the transaction in the current client session that invokes the extended stored procedure.
The extended stored procedure can then use sp_bindsession to bind any new session it creates against the same server to the existing transaction so that the new session can share the same transaction lock space with the client session that invoked the extended stored procedure.
To bind an extended stored procedure session to the client session that called it so they share the same transaction lock space
The extended stored procedure calls svr_getbindtoken to get the bind token for the current transaction in the session. The token is returned in the given bindtoken parameter.
The extended stored procedure opens new session(s) against the same server. Inside that session, the extended stored procedure uses the bind token with sp_bindsession to bind the new session to the same transaction. The extended stored procedure can create multiple sessions and bind all the sessions to the same transaction.
A bound session is unbound when the external stored procedure returns or when sp_bindsession is called with an empty string.
Only one bound session at a time can have access to a shared connection. If one session is currently executing a statement at the server or has results pending from the server, no other sessions sharing the same bound connection can gain access to the server until the current session has finished executing the current statement. If a session attempts to gain access to the connection while the server is busy, an error is returned to the conflicting session indicating the connection is in use and the session should retry later.
You should thoroughly review the source code of extended stored procedures, and you should test the compiled DLLs before you install them on a production server. For information about security review and testing, see this Microsoft Web site.