Distributed transaction within a stored procedure

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.
dbdoshiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

danblakeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dbdoshiAuthor Commented:
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
dbdoshiAuthor Commented:
I finally solved the problem. It was a windows 2003 server issue and netbios name resolution problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.