|
-
Feb 9th, 2010, 01:17 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] all or not at all
Hi,
I have the following code,
code Code:
Try
SqlDataSource1.Insert() ' SAVE TO DATABASE
client2.Send(msg2) ' ----EMAIL TO CLIENT
client.Send(msg) ' -----EMAIL TO OFFICE
service.Insert(postUri, entry)
Catch ex As Exception
Label10.Text = ex.Message
Label10.ForeColor = Drawing.Color.Red
End Try
I would like to run all the 4 lines of code, or none of them. Is it possible?
thx
-
Feb 9th, 2010, 05:03 PM
#2
Re: all or not at all
Look up TransactionScope.
vb Code:
Try Using scope As New TransactionScope() SqlDataSource1.Insert() ' SAVE TO DATABASE client2.Send(msg2) ' ----EMAIL TO CLIENT client.Send(msg) ' -----EMAIL TO OFFICE service.Insert(postUri, entry) scope.Complete() Catch ex As Exception Label10.Text = ex.Message Label10.ForeColor = Drawing.Color.Red End Try
If an error occurs, then scope.Complete isn't called and the transactions are rolled back. However, note that not all parts of your code implement transactions. So if the email sending fails, then your SQL will rollback, but if your service Insert fails, the email cannot be un-sent.
-
Feb 9th, 2010, 05:21 PM
#3
Thread Starter
Frenzied Member
Re: all or not at all
Hi,
There is an error when declaring it as TransactionScope() .
And where shud i put the end using?
thanks
-
Feb 9th, 2010, 05:39 PM
#4
Re: all or not at all
after the scope.complete
-tg
-
Feb 10th, 2010, 02:46 AM
#5
Re: all or not at all
Hey,
What is the error that you are getting?
Can you post the code as you currently have it?
Gary
-
Feb 10th, 2010, 09:48 AM
#6
Thread Starter
Frenzied Member
Re: all or not at all
Type 'TransactionScope' is not defined.
-
Feb 10th, 2010, 09:59 AM
#7
Re: all or not at all
Hey,
So that suggests that you are missing a using/Imports statement. TransactionScope lives in the System.Transactions namespace, so you will need to include this.
Gary
-
Feb 10th, 2010, 01:51 PM
#8
Thread Starter
Frenzied Member
Re: all or not at all
Still there is a problem after importing it
Namespace or type specified in the Imports 'System.Transactions.TransactionScope' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
-
Feb 10th, 2010, 02:10 PM
#9
Re: all or not at all
you import the namespace system.transactions .... TransactionScope is the class... not a namespace, so you do not (cannot) import it.
-tg
-
Feb 10th, 2010, 02:14 PM
#10
Thread Starter
Frenzied Member
Re: all or not at all
Warning 64 Namespace or type specified in the Imports 'System.transactions' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
-
Feb 10th, 2010, 02:43 PM
#11
Re: all or not at all
Hey,
Can you paste the code that you are using, or at least a screenshot of your code file?
Gary
-
Feb 10th, 2010, 04:33 PM
#12
Re: all or not at all
Silly question... but did you first REFERENCE System.Transactions? You need to reference it before you can import it.
-tg
-
Feb 10th, 2010, 04:41 PM
#13
Thread Starter
Frenzied Member
Re: all or not at all
good question, i didn't.
it worked now
Thanks
-
Feb 10th, 2010, 05:07 PM
#14
Re: all or not at all
Ha ha, I didn't think to suggest that, assumed that it would have been done 
Remember to mark your thread as resolved.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|