SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ADO and sp_getapplock


ADO and sp_getapplock

Author
Message
tompic
tompic
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 1
The following attempt to place a transaction lock on
resource XXX always fails with a return value of -999
which I believe indicates that there's no transaction,
contrary to the documentation. If I replace the
transaction with a session lock it works fine, any
ideas?

Dim oParam As ADODB.Parameter
Dim oCmd As ADODB.Command
Dim lRet As Long

m_oConn.BeginTrans

Set oCmd = New ADODB.Command
oCmd.ActiveConnection = m_oConn
Set oParam = oCmd.CreateParameter("return_value", adInteger, _
adParamReturnValue)
oCmd.Parameters.Append oParam
Set oParam = oCmd.CreateParameter("@Resource", adVarChar, _
adParamInput, 255)
oCmd.Parameters.Append oParam
Set oParam = oCmd.CreateParameter("@LockMode", adVarChar, _
adParamInput, 32)
oCmd.Parameters.Append oParam
Set oParam = oCmd.CreateParameter("@LockOwner", adVarChar, _
adParamInput, 32)
oCmd.Parameters.Append oParam

oCmd.CommandText = "sp_getapplock"

oCmd.Parameters("@Resource") = "XXX"
oCmd.Parameters("@LockMode") = "Exclusive"
oCmd.Parameters("@LockOwner") = "Transaction"

oCmd.Execute , , adCmdStoredProc Or adExecuteNoRecords

lRet = oCmd.Parameters("return_value")

m_oConn.CommitTrans



tompic
tompic
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 1
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



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search