We use sp_getbindtoken inside an insert/update trigger in our workflow engine. Just as you describe, we need a way to track all changes within a single transaction, but we cannot require that all code occur within a single stored procedure.
However, we have seen postings that suggest that sp_getbindtoken will be removed after SQL Server 2008. It does work fine for now, so I guess we have 3 years to discover an alternative.
Paul Rony
SplendidCRM Software
Thanks Paul, that's exactly what I was looking for...:)
Paul Rony (1/9/2009)
We use sp_getbindtoken inside an insert/update trigger in our workflow engine. Just as you describe, we need a way to track all changes within a single transaction, but we cannot require that all code occur within a single stored procedure.However, we have seen postings that suggest that sp_getbindtoken will be removed after SQL Server 2008. It does work fine for now, so I guess we have 3 years to discover an alternative.
Paul Rony
SplendidCRM Software
You wouldn't have an example of how you are doing this in the trigger would you?
I've tried this...
BEGIN TRAN;
DECLARE @bind_token varchar(255);
EXECUTE sp_getbindtoken @bind_token OUTPUT
SELECT @bind_token AS Token;
GO
...but it always seems to return the same Token value.
Your code seems correct, but are you committing or rolling back the transaction before running it a second time?
Remember that if you don't, a new transaction will not be started, it's only the transaction counter that will be incremented...
BEGIN TRAN;
update TESTTABLE set Title='MR' where StaffID='2027-sso'
DECLARE @bind_token varchar(255);
EXECUTE sp_getbindtoken @bind_token OUTPUT
SELECT @bind_token AS Token;
COMMIT TRAN
GO
Still get the same Token value every time
Just make sure that there are no open transactions left over from previous attempts.
"SELECT @@TRANCOUNT" should return 0 before you attempt to run it again.
Hope that helps, it definitely works for me...
Thanks - this works fine...
BEGIN TRAN;
DECLARE @bind_token varchar(255);
EXECUTE sp_getbindtoken @bind_token OUTPUT
SELECT @bind_token AS Token;
COMMIT TRAN
GO
...running it several times returns
jNN:fZ63e1K3Z2CE1KkC1=5---.RH---
ZQ/Ka[U;b1O3VV0I>DLZ[]5----QJ---
[T;?]BL7^QSQJh_PaOl@--5---/UJ---
;_0QPEcQeaKT@6^@?VH`<-5----jF---
...and so on.
Is there any guarantee that this value is unique?
We're using this in a trigger to audit changes to multiple tables.
I do not believe that the values are globally unique, but I suspect that they are unique for a single system.
Viewing 15 posts - 1 through 15 (of 22 total)
You must be logged in to reply to this topic. Login to reply