Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 ROLLBACK TRANSACTION statement

Author  Topic 

Rocko
Starting Member

26 Posts

Posted - 2006-05-24 : 16:02:47
Hello


I’m using the procedure below with Transactions. I want to have a backup record in case somebody updates a contact profile. I wanted to test how the transactions are working and renamed with purpose the column LastName from ContactBackup table to LastName2. Then I’m getting the following error message:

Message	"Invalid column name 'LastName'.
Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing.
Previous count = 0, current count = 1.

I was wondering what it means. Is something wrong with my Trans syntax?

Below is the procedure:

ALTER PROCEDURE [dbo].[wsp_UpdateContactProfile]
(
@contactCode char(30),
@prefix char(20),
@firstName char(50),
@middleName char(50),
@lastName char (50)
)
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRAN
-- Will create a backup record of existing Contact
INSERT INTO ContactBackup(ContactCode,
Prefix,
FirstName,
MiddleName,
LastName)
VALUES(@contactCode,
@prefix,
@firstName,
@middleName,
@lastName)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
return 10
END

UPDATE Contact SET
Prefix = @prefix,
FirstName = @firstName,
MiddleName = @middleName,
LastName = @lastName
where contactCode = @contactCode
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
return 11
END

COMMIT TRAN
END
GO


Thanks in advance!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-05-24 : 16:33:09
quote:

I wanted to test how the transactions are working and renamed with purpose the column LastName from ContactBackup table to LastName2.



Your transaction is coded properly. The change that you made is considered a fatal error. What you can do to test the transaction is try inserting a record that violates the primary key. This is the type of thing that a transaction is there for.

Tara Kizer
aka tduggan
Go to Top of Page

Rocko
Starting Member

26 Posts

Posted - 2006-05-25 : 09:21:30
Ok, Thanks. I was just wondering what does it means a ….COMMIT or ROLLBACK TRANSACTION statement is missing.
I don’t have that much experience with trans and I though that may need another ROLLBACK TRANS for both statements.
Thanks!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-05-25 : 12:28:58
Your transaction is coded properly. Ignore that error as what you were testing wouldn't have used the transaction.

Tara Kizer
aka tduggan
Go to Top of Page
   

- Advertisement -