using transactions

Topics: Data Access Application Block
Oct 11, 2010 at 11:45 AM

Hi,

I'm having some problems with transactions. I want to create an invoice and its line in a transaction (simplified example). This is what I do:

I create the invoice with an executescalar method from a SQLDataBase entlib object, it is a static instance. It returns me the invoice generated ID (identity column in the database), but the invoice it is not in the database! I create the invoice lines, and there are no errors... but, then, I go to the database and there is not invoice and neither its lines! But the curious thing is that if I insert a register to the database with a "manual" "insert into" (using the sql server management studio query window), the next autogenerated ID is my previous invoiceId + 1. I mean, it seems the register is not inserted but the ID is reserved, or something like that. This is giving me a lot of problems. Any idea?

Thanks.

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    invoiceId = createInvoice()  //->method that simply wraps a db.executescalar() (the db is an static instance)

    createInvoiceLines(invoiceId) 
}

Oct 12, 2010 at 12:06 AM

It would seem that there was an error while executing createInvoiceLines.  Does your stored procedure contains error handling which might explain why there was no exception being thrown in your program? 

Would it be possible for you to send a small repro?

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Oct 12, 2010 at 6:43 AM
Hi,

I don't think its an error. It does not work with the more simple of querys. It works perfectly if I call this method before leave the "using" sentence: "complete()"

http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.complete.aspx

I think the documentation should be reviewed or better explained, because without this it didn't worked for me and I wasted a lot of time... :(


Regards,


Jesús Bosch Aiguadé
Microsoft Student Partner | MCPD
http://geeks.ms/blogs/jbosch








From: [email removed]
To: [email removed]
Date: Mon, 11 Oct 2010 17:06:17 -0700
Subject: Re: using transactions [entlib:230409]

From: AvanadeSupport
It would seem that there was an error while executing createInvoiceLines. Does your stored procedure contains error handling which might explain why there was no exception being thrown in your program?
Would it be possible for you to send a small repro?

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Read the full discussion online.
To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com)
To start a new discussion for this project, email entlib@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Oct 12, 2010 at 7:18 AM
Edited Oct 12, 2010 at 7:19 AM

I forgot about calling explicitly the Complete method, sorry about that.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com