dbdoshi
asked on
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,b d)
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.
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,b
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I finally solved the problem. It was a windows 2003 server issue and netbios name resolution problem.
ASKER