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


Distributed Transaction


Distributed Transaction

Author
Message
Tom.Bauto
Tom.Bauto
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 37
Good Day,

I'm new to Distributed Transaction, and i'm getting this error

Server: Msg 7377, Level 16, State 1, Line 5
Cannot specify an index or locking hint for a remote data source.

I need to have the locking hint within my query, but i have to connect onto another server so I have to use the distributed transaction for me to be able to create a transactional query.

This is my situation:

my PC is in 192.168.1.101 and the server in on 192.168.1.100
I am testing this query:

BEGIN TRANSACTION

DECLARE @ID AS BIGINT

SELECT TOP 1
@ID = [ID]
FROM [192.168.1.100].SERVER_DB.DBO.TEST_TABLE
WITH(UPDLOCK)
WHERE
ROWLOCKED = 0 AND
ISPROCESSED = 0

COMMIT TRANSACTION

now im stuck : (

Please I need your expertise on this.

Thanks!

_____________________________________________
ToM™ (Possibility will come out of nothing)
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85300 Visits: 41078
You cannot use locking hints that way... period. Wink

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
GilaMonster
GilaMonster
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86731 Visits: 45254
As Jeff said, not possible.

I'm curious. Why would you want to do a select with an UPD lock and then immediately commit the transaction? You're not achieving anything as the lock will be dropped as soon as the transaction commits.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Jacob Luebbers
Jacob Luebbers
Mr or Mrs. 500
Mr or Mrs. 500 (580 reputation)Mr or Mrs. 500 (580 reputation)Mr or Mrs. 500 (580 reputation)Mr or Mrs. 500 (580 reputation)Mr or Mrs. 500 (580 reputation)Mr or Mrs. 500 (580 reputation)Mr or Mrs. 500 (580 reputation)Mr or Mrs. 500 (580 reputation)

Group: General Forum Members
Points: 580 Visits: 1215
Create a stored proc on the remote server that encapsulates your logic, and execute it from the local server. You should be able to use your locking hints in it with no problems.

It's generally best to use procs across a remote server boundary in many cases - avoids the chance that the local server will try to drag any of the remote tables across to resolve your criteria. Not appropriate for all cases, but I find that the majority perform better using procs.

Regards,

Jacob
Tom.Bauto
Tom.Bauto
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 37
Thanks guys! My situation is this; I have source table from a server which is my Inbox.tbl and I have multiple instance of application that continuously reading this table ex:

DECLARE
@MESSAGE AS VARCHAR(200) ,
@INBOXID AS BIGINT

SELECT
@INBOXID = INBOXID ,
@MESSAGE = MESSAGE
FROM INBOX
WITH(UPLOCK)
WHERE
ROWLOCKED = 0 AND
ISPROCESSED = 0

IF @INBOX IS NOT NULL /* RETRIEVED RECORD */
BEGIN

/* MARK THE TABLE AS LOCKED */
UPDATE INBOX
SET
ROWLOCKED = 1
WHERE
INBOXID = @INBOXID

At this point, since I have retrieved a record, I have to call a stored procedure located at another database server to process the request based from the catch message “@MESSAGE

But in my query I have to continuously hold the transaction; that’s why im using the distributed transaction.

END




But as of my workaround permits, I put my parsing code onto another server which uses XLOCK and its quite working now.

_____________________________________________
ToM™ (Possibility will come out of nothing)
Tom.Bauto
Tom.Bauto
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 37
Actually Gila, I do it because I have multiple instance of application which calls this stored procedure, the duty of this SP is to get new request from my inbox table, but without duplication of transaction, because some of this request has account transaction.

_____________________________________________
ToM™ (Possibility will come out of nothing)
Gary Johnson-259336
Gary Johnson-259336
SSC-Enthusiastic
SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)

Group: General Forum Members
Points: 197 Visits: 184
Try adding the keyword "DISTRIBUTED" to your begin transaction statement.

IE:

BEGIN DISTRIBUTED TRANSACTION
...


This will change the way the transaction locks data. I'm pretty sure I had that working with SQL 2000. It does take the correct server setup to get working though.

Gary Johnson
Sr Database Engineer
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