• More info ...

    I changed the code above to call the stored procedure below, first allowing the result from the call to sp_getapplock to flow back to the VB code, the result was 0 and I could see the lock in enterprise manager, then to return the trancount as shown below. The trancount is 2. So I looked at the sp_getapplock source and see that the error I get indicates that trancount is 0, is there a visibility problem with system stored procedures? I hate to implement this workaround without knowing whats really wrong.

    CREATE PROC AppLockId

    AS

    SET NOCOUNT ON

    DECLARE @result int

    begin tran

    Exec @result = sp_getapplock @Resource = 'XXX',

    @LockMode = 'Exclusive',

    @LockOwner = 'Transaction'

    @result = @@trancount

    commit tran

    return @result

    GO