Re: inserting into two tables and transaction problem





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


.



Relevant Pages

  • Re: Stamps.com Warning
    ... Customers using PayPal MasterCard Debit Cards are seeing what they ... authorization to bill but does not bill the actual transaction. ... Stamps.com Postage Group ... requested and the duplicate request stamps.com sends is withdrawn from ...
    (alt.marketing.online.ebay)
  • Re: Stamps.com Warning
    ... Customers using PayPal MasterCard Debit Cards are seeing what they ... authorization to bill but does not bill the actual transaction. ... Stamps.com Postage Group ... requested and the duplicate request stamps.com sends is withdrawn from ...
    (alt.marketing.online.ebay)
  • Re: Running Query classes inside transactions
    ... I'm assuming that 'thisquery' is a DAO QueryDef? ... the relationship between Customers and Orders (otherwise you'd get an RI ... Set rst = db.OpenRecordsetAS TheCount FROM Customers ... Debug.Print "Within transaction ..." ...
    (microsoft.public.access.queries)
  • Re: Multithreaded Database access with C# on an Sql2005 and TransactionScope class (Bug or did I som
    ... der zuerst geschlossen werden muss.\r\n bei ... Console.WriteLine("About to complete the worker3 thread's transaction ... The real Programm should calculate some values for Customers. ... Threads with differend Customer-Ids and do data reading and calculating of ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Correct me if Im wrong ...
    ... "My plan will also ensure that Borland's customers and employees are made ... For that reason I would favor a transaction for Delphi that ... separation. ...
    (borland.public.delphi.non-technical)