try catch finally / response.redirect / response.end flow control question

Hi Guys,

Can any one tell me if the finally block would be executed in the following example (assuming that returned false because no records were found).  

Many Thanks!


  dbCon = New SqlConnection(myconnectionstring)
  dbCom = dbCon.CreateCommand()				
  strSQL + "SELECT * FROM bookings WHERE ID > 9000"
  dbCom.CommandText = strSQL
  dbReader = dbCom.ExecuteReader()
  If dbReader.Read() Then
    'init fields
  End if
  dbReader = nothing
  dbCom = nothing
  dbCon = nothing
End Try
3/25/2009 4:12:27 PM 91979 articles. 4 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 12

The Finally block always executes... no matter what.

Steve Wellens

My blog
3/25/2009 4:28:38 PM

Similar Artilces:

Response.Redirect and Try Catch Finally
If I have a Try Catch Finally block with a Response.Redirect in the Catch and a Connection.Close in the Finally, will the code in the Finally still execute before the Redirect takes place? Someone asked a similar question at this web site: Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Thanks for the link. Can anyone confirm that, yes, the Finally will execute? Yes,it will execute....

No response from response.redirect
Hi, my project has atleast 10 webforms and for navigation the response.redirect was working fine till today. It stopped working in one of the pages but stills fine in the other pages. eg. the CANCEL button loads the previously navigated page. All CANCEL except one are working. I checked the button click event, put labels with messages in them; the labels get posted when the button is clicked; but when i remove the labels and put in the response.redirect("PAGE NAME") it stopped working; i even put the wrong path in the response.redirect, still the errorhandler or any o...

Try..Catch and Response.Redirect
I have sub that connect to a db to verify users. If the user is cleared the they are redirected to the next page and if not then they are forced to login again. I have noticed that during debug on my Try..Catch..Finally block an error is always fired on the resposne.redirect. Dim rs As SqlDataReader = objCMD.ExecuteReader If rs.Read() = False Then Response.Redirect("issuenewrga.aspx?OrderNum=" & txtOrderNum.Text & "&ItemNum=" & txtItemNum.Text & "&LineNum=" & txtLineNum.Text) ...

try, catch, Response.Redirect problem
Hi,This is the code which makes me a problem: try{ Response.Redirect("SomePage.aspx");}catch{ ...someOperation():} It always goes to catch region...  i think you don't have that page in your web server. check it first.Got what you needed. Please mark as answer. This is a known issue, try to use the below code try {Response.Redirect("WebForm2.aspx",false);     }catch(Exception ex) { Response.Write(ex.Message); } HCHaissam Abdul MalakMCAD.NET| Blog | Sathesh_pandian:i think you don't have that page in your we...

Try catch, Response.Redirect, and endResponse
 Hi,I get an error email from this aspx page once a while. I have pasted the code skeleton below. The error email says the error occured at the line marked *, where sproc1 is being called. When I look up the database table, I see the sproc2 has been executed as well. I created a test page and changing the endResponse parameter to true or false did not make any difference, when an exception occurs the execution always jumps straight to the catch block. I wish the same thing was happening in the production page as well, but the sproc2 is always being called.try{    .....&nb...

Response.Redirect within Try Catch
Hi, I am using 2.0 and I have a page where I need to use the Try-Catch-Finally structure. Within the Try statement I have various commands and then at the end of it I have a Response.Redirect("....") to take the user to another page. Within my catch statement I also have a Response.Redirect("../errorPage.htm") which will take you to the error page if any exceptions occur. However, I have tested the page and I know there are no exceptions happening but the user is still getting redirected to the error page.  Is there anyway to make this not happen? I am using Smart Navigatio...

differnence between Response.Redirect() and Server.Transform() Flow between Request and Response
HiWhat is the differnence between Response.Redirect() and Server.Transform() Some body telling Response.Redirect will increase one request between client and Web Server Can anyone explain detail the Flow.(between Request and Response) Regards,Janakaraj   Server.Transfer just tells ASP.NET to now move to a new page, much like setting focus. The client is not aware of this at all so the URL stays the same. This can be a disadvantage.Response.Redirect actually tells the client we are going to redirect your request to a new page hence there is extra overhead in adding new header...

response.redirect inside a Try Catch...
I’ve come across a situation where I have a response.redirect inside a TRY Catch The redirect seams to trigger an exception.   I found a work around but I’m scared it might cause other problems.   Response.redirect(“blah blah”, False)    ß the false seams to help … although I’m not 100% sure why …   You guys see any problem in this solution?   It should be ok. The second argument means whether the execution of the current page should be stopped or not. When you specified false, it means if should not stop and thus no error otherwise previosly it...

How can I get a Response.Write and Response.Redirect to work one following the other?
I have a button on my webform that needs to perform 2 operations.  First it must open a new window which I usually do like this: sJScript = "<script>'Form01.aspx?ID=0&Parent=5', '', '');</script>"Response.Write(sJScript)Second it must redirect the current page (not the newly opened one).  I usually do that like this:Response.Redirect("Form02.aspx?ID=6")My problem is, in this case, I must do both with one button click and they interfere with each other.  I've tried flushing/ending the response object in various places, re ordering things, etc but n...

Response.redirect without exception in a try catch?
I have these code: try{ if(!fuFaxnummer.PostedFile.FileName.EndsWith(".csv")){ Response.Redirect("faxnummerimport.aspx?ID=" + id + "&msg=2"); } //code to execute when the file is a .csv } catch (exception ex){ LogDA.insertLog(...); Response.Redirect("error.aspx"); }I know that "Response.Redirect" gives an Exception. When I set the bool endResponse at false (Response.redirect("",false)) there is no exception BUT he execute the code behind my IF(). Someone with a solution?      ...

Response.Redirect inside a Try Catch block
Can you put a Response.Redirect inside a Try Catch block?I think you will get a thread Abored Error, true? Who said so? I just tried it and it worked fine!!!!What is mainly the problem you are facing?RegardsBilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

Response.write or Response.redirect?
I have a code using Response.Write and javascript to open another page, the code looks like this: Response.Write("<Script language='javascript'>'" & Session("varflag") & "&vid=" & Session("FacilityID") & "&vrepid=" & Session("varid") & "');</script>") it send me to another page in a different window or tab. I want to open it in the same window or tab as in Response.Redirect, but in Respons...

Will finally execute if response.end is in catch block?
try     'some code here causes exception catch     'some exception code     Response.End() finally 'will any code here be executed since it is after the response.end end try Thanks! Yes - the code in the Finally block will run.  Infact, if you put a Response.Write("Hello") in your Finally block, it will write it out even though the Response.End() was called in the Catch block. (Example for the Finally key word)that is why you need to catch error for opening connection to DB and finally will have the 'con.close...

Delete command in GridView with response.redirect in a try catch
 Hi, I have these code: protected void gvFaxLijst_RowCommand(object sender, GridViewCommandEventArgs e){try{if (e.CommandName == "Delete"){//codeResponse.write("index.aspx",false);}}catch(exception ex){insertlog(...);Server.Transfer("error.aspx");}The problem is that the Delete command isn't finished so I got an error (System.Web.HttpException)When i remove the False in Response.write("index.aspx") then I got these error:  [System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a...

Web resources about - try catch finally / response.redirect / response.end flow control question -

Wikipedia:Abuse response - Wikipedia, the free encyclopedia
For a list of current Abuse Response volunteers, or for information on how you can help with the Abuse Response project, please see the volunteers ...

Esperance bushfires: WA firefighters cop flak for response time
Firefighters have been forced to defend themselves after being criticised for response times to the deadly bushfires in Western Australia's south. ...

Justin Trudeau's toast to the Queen elicits cheeky royal response
... Minister Justin Trudeau's toast to Queen Elizabeth at the Commonwealth leaders' summit dinner in Malta on Friday elicited a rather cheeky response ...

Networks to Meet Monday on Response to Trump
The major cable and broadcast news networks will meet Monday to discuss a joint response to the presidential campaign of Donald Trump , which ...

The perfect response to Joyce Carol Oates.
. @JoyceCarolOates you were great in 'The Shining' — David Burge (@iowahawkblog) November 23, 2015

Russia's response: Surface-to-air missiles in Syria
Tension mounts as Moscow moves its most advanced anti-aircraft missiles near to where fighter jet was downed in move Putin called a "stab in ...

Obama Paris Speech: Action On Global Warming Is Best Response To ISIS
Obama Paris Speech: Action On Global Warming Is Best Response To ISIS

Viacom CEO Philippe Dauman Says Sumner Redstone “Engaged & Attentive” In Response To Lawsuit
... chairman's "living ghost" of a life but his corporate right hand man says the boss is still in good shape. In papers filed today in response ...

Kim Kardashian Shares Throwback Photo Dressed as a Spice Girl See Victoria Beckham's Response!
Kim Kardashian Shares Throwback Photo Dressed as a Spice Girl See Victoria Beckham's Response!

How To Use AutoCorrect In Microsoft Office To Create Your Own Boilerplate Responses
AutoCorrect is a pretty amazing thing…most of the time. I’m not a huge fan of the autocorrect function in iOS all the time—or it’s tendency to ...

Resources last updated: 11/30/2015 9:33:52 PM