Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Inserting Record - Catching Exceptions

Started 1 month, 3 weeks ago by imchaz
I have a button if the user clicks on it here are the following actions. 1. Inserts Record into Table A 2. Inserts Record into Table B 3. Sends Email of the Transaction occured. If it fails inserting in Table A or Table B or has problem connecting to the mail server to send an email of the transaction, I need the action stop and and prevent the action from inserting records into Table A and...
Site: Forums - ASP.NET Forums  Forums - ASP.NET Forums - site profile
Forum: Data Access and ObjectDataSource Control  Data Access and ObjectDataSource Control - forum profile
Total authors: 4 authors
Total thread posts: 15 posts
Thread activity: no new posts during last week
Domain info for: asp.net

Other posts in this thread:

mkamoski replied 1 month, 3 weeks ago
I think one way to do it is to create and explicit transaction and assign it to the Command object... ...as noted here... http://www.c-sharpcorner.com/UploadFile/dchoksi/tr ansaction02132007020042AM/transaction.aspx ...so I HTH... Thank you. -- Mark Kamoski

imchaz replied 1 month, 3 weeks ago
mkamoski: I think one way to do it is to create and explicit transaction and assign it to the Command object... ...as noted here... http://www.c-sharpcorner.com/UploadFile/dchoksi/tr ansaction02132007020042AM/transaction.aspx ...so I HTH... Thank you. -- Mark Kamoski Thanks for the link and its very similar in what I am doing, inserting records using ...

mkamoski replied 1 month, 3 weeks ago
Make sure you are not running your... Trans.Commit(); ...until after the email is sent... ...which might be a long wait... ...but, wait and if it times out or whatever, do a Trans.Rollback call... ...if you need the results of your insert to include in your email, then you might be stuck, because those actual results of the insert will not be really available until after the Commit......

imchaz replied 1 month, 3 weeks ago
mkamoski: Make sure you are not running your... Trans.Commit(); ...until after the email is sent... ...which might be a long wait... ...but, wait and if it times out or whatever, do a Trans.Rollback call... ...if you need the results of your insert to include in your email, then you might be stuck, because those actual results of the insert will not be really available until ...

Babunareshnarra replied 1 month, 3 weeks ago
imchaz: 1. Inserts Record into Table A 2. Inserts Record into Table B 3. Sends Email of the Transaction occured. First execute the steps 1 and 2 in a transaction and return a bool value from the method which is performing steps 1 & 2. If it returns true send email else show ur msg. there is another way in ur query check if @param is null if so set @param=0 and use 2 queries one ...

imchaz replied 1 month, 3 weeks ago
Babunareshnarra: imchaz: 1. Inserts Record into Table A 2. Inserts Record into Table B 3. Sends Email of the Transaction occured. First execute the steps 1 and 2 in a transaction and return a bool value from the method which is performing steps 1 & 2. If it returns true send email else show ur msg. there is another way in ur query check if @param is null if so set @param=...

mkamoski replied 1 month, 3 weeks ago
imchaz -- Regarding this... >>>Here is my code if this helps. I ...I think that I may see the issue... ...in your SendMailA() method, you catch and handle several excpetion cases... ...I think you cannot do it that way and I think the design needs to be changed to get the transaction to work the way you want... ...note that Rollback only occurs in the SendEmail() controller ...

imchaz replied 1 month, 3 weeks ago
mkamoski: ...when an exception occurs in SendMailA, you need to break hard and throw an exeception which will allow the controller method SendEmail() to Rollback in ALL cases... Can you give an example on how to modify this? I just cant get my head around on the modification. Thanks for your replies. -Chuck

Wencui Qian - MSFT replied 1 month, 3 weeks ago
Hi imchaz, A transaction is used for database exceptions. Since sending a mail can't cause a sql exception, it'll not impact the finish of a transaction. Thus I just wonder whether you can try to throw a sql exception if the mail server is wrong so that it may let the transaction rollback. Please try it first. Thanks.

Babunareshnarra replied 1 month, 3 weeks ago
imchaz: Babunareshnarra: imchaz: 1. Inserts Record into Table A 2. Inserts Record into Table B 3. Sends Email of the Transaction occured. First execute the steps 1 and 2 in a transaction and return a bool value from the method which is performing steps 1 & 2. If it returns true send email else show ur msg. there is another way in ur query check if @param is null ...

 

Top contributing authors

Name
Posts
imchaz
6
user's latest post:
Inserting Record - Catching...
Published (2009-11-18 17:47:00)
Thank you for your detailed solution. 
mkamoski
6
user's latest post:
Inserting Record - Catching...
Published (2009-11-19 13:32:00)
imchaz -- Here is a better refactoring of one of those methods...   Protected Sub SendEmail_New_New( _ ByVal sender As Object, _ ByVal e As System.EventArgs _ ) Handles sendEmailButton.Click Dim conn As SqlConnection = Nothing Dim myTrans As SqlTransaction = Nothing Try conn = New SqlConnection(GetConnectionString()) conn.Open() myTrans = conn.BeginTransaction() InsertNumberA(conn, myTrans) InsertNumberB(conn, myTrans)...
Babunareshnarra
2
user's latest post:
Inserting Record - Catching...
Published (2009-11-16 02:01:00)
imchaz: Babunareshnarra: imchaz: 1.  Inserts Record into Table A 2.  Inserts Record into Table B 3.  Sends Email of the Transaction occured. First execute the steps 1 and 2 in a transaction and return a bool value from the method which is performing steps 1 & 2. If it returns true send email else show ur msg. there is another way in ur query check if @param is null if so set @param=0 and use 2 queries one...
Wencui Qian - MSFT
1
user's latest post:
Inserting Record - Catching...
Published (2009-11-16 01:17:00)
Hi imchaz, A transaction is used for database exceptions. Since sending a mail can't cause a sql exception, it'll not impact the finish of a transaction. Thus I just wonder whether you can try to throw a sql exception if the mail server is wrong so that it may let the transaction rollback. Please try it first. Thanks. 

Related threads on "Forums - ASP.NET Forums":

Related threads on other sites:

Thread profile page for "Inserting Record - Catching Exceptions" on http://www.asp.net. This report page is a snippet summary view from a single thread "Inserting Record - Catching Exceptions", located on the Message Board at http://www.asp.net. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity