Solved

Distributed transaction within a stored procedure

Posted on 2004-10-21
254 Views
Last Modified: 2008-01-09
Hi, I have stored proc which goes something like this:

CREATE PROC sch_update_ccnd ( @ssn varchar(10), @bd datetime)
AS

DECLARE @trncnt int
SELECT @trncnt = @@trancount

IF @trncnt = 0
      BEGIN DISTRIBUTED TRAN succnd
ELSE
      SAVE TRAN succnd

IF EXISTS (SELECT ssn FROM int_lukebox.db.dbo.T WHERE ssn=@ssn)
BEGIN
      UPDATE int_lukebox.db.dbo.T
          SET bd=@bd
          WHERE ssn = @ssn
END
ELSE
BEGIN
      INSERT INTO int_lukebox.db.dbo.T(ssn,bd)
      VALUES(@ssn,@bd)
END

IF (@@ERROR != 0)
BEGIN
      ROLLBACK TRAN succnd
      RETURN -999
END

IF @trncnt = 0
      COMMIT TRAN succnd

RETURN 0
GO


This thing just hangs and never returns. Any pointers will be appreciated. If I remove all the transactional stuff from it, it executes fine. So something to do with distributed transactions and linked servers. BTW, the security context of the linked server has both read and write priviledges on both the servers.
0
Question by:dbdoshi
    3 Comments
     
    LVL 13

    Accepted Solution

    by:
    You should be able to cut-down the code, slightly with the following structure:

    IF @@TRANCOUNT = 0
      BEGIN DISTRIBUTED TRAN succnd
    ELSE
      SAVE TRAN succnd

    ..
    ..
    IF (@@ERROR != 0) COMMIT TRAN
    ELSE
    BEGIN
       ROLLBACK TRAN
       RETURN -9999
    END

    RETURN 0

    When you place a few PRINT statements in this procedure, where does it stop or hang?
    Check the SQL Server Log for any error messages from the MS DTC Component.
    Also does the MS DTC have permissions on both servers ?  (Is MS DTC Running at all -- this is what actually runs the and manages the distributed transactions).
    0
     

    Author Comment

    by:dbdoshi
    I searched through the web and on one of the microsoft KB articles they say that savepoints are not allowed in distributed transactions, unless you start the sql server with a particular trace flag.
    0
     

    Author Comment

    by:dbdoshi
    I finally solved the problem. It was a windows 2003 server issue and netbios name resolution problem.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    860 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now