1 2 createproceduresp_start_xact3 @applname varchar(30),4 @xactname varchar(30),5 @count smallint,6 @password varchar(30)=NULL7 AS8 9 declare@xid binary(140)10 declare@randid int
11 12 if @@trancount = 0
13 begin14 settransactionisolationlevel 1
15 set chained off16 end17 18 set nocount on19 20 BEGIN21 BEGINTRANSACTION22 select@xid=convert(binary(140), 0x0)23 24 /*
25 ** Get a random commid to reduce the page lock contention
26 ** during insert. Note that there is a possibility of
27 ** inserting a duplicate row. If we do, then repeat the
28 ** insert with another commid until we are successful.
29 ** The probability is extremely low since we can have
30 ** atleast 2 billion combinations (2147483647 to be precise)
31 ** for the commid.
32 */33 while(1 = 1)34 begin35 /* Select a random commid between 1 and 2147483647 */36 select@randid= rand()* 2147483647
37 INSERTsybsystemdb.dbo.spt_committabVALUES38 (39 @randid,40 - 1,/* this tells us that this is a non-XA 2pc */41 getdate(),42 getdate(),43 @count,44 @count,45 'n',46 'b',47 @xid,48 @applname,49 @xactname,50 @password51 )52 53 /*
54 ** If we attempted to insert a duplicate row into the
55 ** table we would have got a 2601 error. But we have
56 ** some special checks in dupcheck() routine which will
57 ** avoid printing the error message if the object is
58 ** spt_committab. So, the user will not see an error
59 ** message in this situation. If we get a 2601 error,
60 ** should try a different random commid.
61 */62 if(@@error = 2601)63 continue64 else65 /* Insert was successful. */66 break67 end68 69 if @@trancount = 0
70 begin71 return 1
72 end73 74 SELECT@randid75 COMMITTRANSACTION76 END77
exec sp_procxmode 'sp_start_xact', 'AnyMode'
go
Grant Execute on sp_start_xact to public
go