You are here: Re: inserting into two tables and transaction problem « MsSQL Server « IT news, forums, messages
Re: inserting into two tables and transaction problem

Posted by Joe Weinstein on 06/30/06 19:03

Habib wrote:

> CREATE PROCEDURE SimpleInsert (
> @custname custname_type,
> @carname carname_type)
>
> AS
>
> BEGIN TRANSACTION
>
>
> INSERT Customers (CustName) VALUES (@custname)
> IF @@error <> 0 BEGIN ROLLBACK TRANSACTION RETURN 1 END
>
> DECLARE @custid int
> SELECT @custid = scope_identity()
>
>
> INSERT Cars (ID, CarName) VALUES (@custid, @carname)
> IF @@error <> 0 BEGIN ROLLBACK TRANSACTION RETURN 1 END
>
> COMMIT TRANSACTION
>
>
> IF no error this works but to test transaction, I chanded the table
> name of second insert to 'car' in which doesn't exist and this error
> occured (calling sp by ASP .NET page):
>
>
> Invalid object name 'car'. Transaction count after EXECUTE indicates
> that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous
> count = 0, current count = 1.

Recompile the procedure. If you rename the table the procedure's
stored query plan is invalid. You have found a type of error for
which a procedure will not continue. If you simply want to test
the transaction, make a unique index on the Customers.CustName
column, and then try to run the procedure twice with the same
customer name.

Joe Weinstein at BEA Systems
>
>
> Thanks
>
> Habib
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация