Distributed Transaction

  • 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!

    _____________________________________________
    [font="Verdana"]ToM™[/font] (Possibility will come out of nothing)

  • You cannot use locking hints that way... period. 😉

    --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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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
  • 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

  • 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) ,

    @INBOXIDAS 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.

    _____________________________________________
    [font="Verdana"]ToM™[/font] (Possibility will come out of nothing)

  • 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.

    _____________________________________________
    [font="Verdana"]ToM™[/font] (Possibility will come out of nothing)

  • 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

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply