Results 1 to 14 of 14

Thread: [RESOLVED] all or not at all

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Resolved [RESOLVED] all or not at all

    Hi,

    I have the following code,
    code Code:
    1. Try
    2.                 SqlDataSource1.Insert() ' SAVE TO DATABASE
    3.                 client2.Send(msg2) ' ----EMAIL TO CLIENT
    4.                 client.Send(msg) ' -----EMAIL TO OFFICE
    5.                 service.Insert(postUri, entry)
    6.  
    7.             Catch ex As Exception
    8.                 Label10.Text = ex.Message
    9.                 Label10.ForeColor = Drawing.Color.Red
    10.  
    11.             End Try

    I would like to run all the 4 lines of code, or none of them. Is it possible?

    thx

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: all or not at all

    Look up TransactionScope.

    vb Code:
    1. Try
    2.    Using scope As New TransactionScope()
    3.  
    4.                 SqlDataSource1.Insert() ' SAVE TO DATABASE
    5.                 client2.Send(msg2) ' ----EMAIL TO CLIENT
    6.                 client.Send(msg) ' -----EMAIL TO OFFICE
    7.                 service.Insert(postUri, entry)
    8.     scope.Complete()
    9.             Catch ex As Exception
    10.                 Label10.Text = ex.Message
    11.                 Label10.ForeColor = Drawing.Color.Red
    12.  
    13.             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.

  3. #3

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    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

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: all or not at all

    after the scope.complete

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  6. #6

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: all or not at all

    Type 'TransactionScope' is not defined.

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  8. #8

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    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.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    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.

  11. #11
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: all or not at all

    good question, i didn't.

    it worked now

    Thanks

  14. #14
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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
  •  



Click Here to Expand Forum to Full Width