inserting into two tables and transaction problem



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.


Thanks

Habib

.



Relevant Pages

  • Re: inserting into two tables and transaction problem
    ... DECLARE @custid int ... IF no error this works but to test transaction, ... Invalid object name 'car'. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Re: OT Buying a Car: In a Patriotic Style
    ... >>I haven't been in the car market recently, so was a little surprised when I ... >>went to complete my transaction yesterday. ... >> efforts to assure that I'm not trying to launder dirty money. ... > been reiterated in the Patriot Act but it predates that act by decades. ...
    (alt.smokers.pipes)
  • =?ISO-8859-1?Q?Re=3A_Help=21_TfL_have_just_nicked_=A3651_from_me=21?=
    ... but it isn't an actual transaction and doesn't go on the ... pre-authorisation process, so it seems that this operation is deliberate. ... days that I had the car). ... original pre-authorisation as the basis for the final transaction. ...
    (uk.transport.london)
  • Re: OT Buying a Car: In a Patriotic Style
    ... >I haven't been in the car market recently, so was a little surprised when I ... >went to complete my transaction yesterday. ... > efforts to assure that I'm not trying to launder dirty money. ... been reiterated in the Patriot Act but it predates that act by decades. ...
    (alt.smokers.pipes)
  • Re: A Glaring Lack of the Obvious
    ... When you rent a car, you probably don't and the rental company surely ... debit account - and then returned the car a day late with an empty ... transaction put a $200 "hold" on the account. ... Same thing happens with credit cards, ...
    (rec.arts.sf.written)