![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | What's wring with this try-catch block? This is freaking me out. I'm using Membership and trying to determine if the database is online. The GetConnectionString( ) method returns a connection string as expected but not when used in the try block. I have the Open() and Close() methods commented out while using the Response.Redirect to test. The code in the try block as shown will --never execute-- but the code in the catch block --always executes-- whether the database is online or not. WTF??? protected void LoginButton_Click(object sender, EventArgs e) { // Redirect proves this test works //Response.Redirect(ResolveUrl("~/homepage.aspx?LoginButton_Click")); SqlConnection testConnection = new SqlConnection(GetConnectionString("MyConnectionString")); if (!String.IsNullOrEmpty(testConnection.ToString())) { try { //testConnection.Open(); //testConnection.Close(); Response.Redirect(ResolveUrl("~/homepage.aspx?MyConnectionString-Found")); } catch (Exception ex) { Response.Redirect(ResolveUrl("~/homepage.aspx?LoginButton_Click-Caught-Exception")); } } } |
My System Specs![]() |
| | #2 (permalink) |
| | Re: What's wring with this try-catch block? Why not simple set a breakpoint behind this part of code and see what it is? testConnection.ToString()) "HillBilly" <somebody@xxxxxx> schreef in bericht news:urnrWn48IHA.4088@xxxxxx Quote: > This is freaking me out. I'm using Membership and trying to determine if > the database is online. The GetConnectionString( ) method returns a > connection string as expected but not when used in the try block. > > I have the Open() and Close() methods commented out while using the > Response.Redirect to test. > The code in the try block as shown will --never execute-- but the code in > the catch block --always executes-- whether the database is online or not. > > WTF??? > > protected void LoginButton_Click(object sender, EventArgs e) > { > // Redirect proves this test works > //Response.Redirect(ResolveUrl("~/homepage.aspx?LoginButton_Click")); > > SqlConnection testConnection = new > SqlConnection(GetConnectionString("MyConnectionString")); > if (!String.IsNullOrEmpty(testConnection.ToString())) > { > try > { > //testConnection.Open(); > //testConnection.Close(); > > Response.Redirect(ResolveUrl("~/homepage.aspx?MyConnectionString-Found")); > } > catch (Exception ex) > { > > Response.Redirect(ResolveUrl("~/homepage.aspx?LoginButton_Click-Caught-Exception")); > } > } > } |
My System Specs![]() |
| | #3 (permalink) |
| Vista Business x64 | Re: What's wring with this try-catch block? I'd have to look this up - I know a Server.Redirect that occurs within the try of a try..catch block throws a thread termination exception. Perhaps Response.Redirect does as well. To fix it, just use Response.Redirect(url,false) instead, or you can throw an extra chunk between your try and catch blocks: catch (System.Threading.ThreadAbortException ex) {//Do nothing } |
My System Specs![]() |
| | #4 (permalink) |
| | Re: What's wring with this try-catch block? "breitak67" <guest@xxxxxx-email.com> wrote in message news:191e700f3beb17bd2df5d7fe780b4959@xxxxxx-gateway.com... Quote: > > I'd have to look this up - I know a Server.Redirect that occurs within > the try of a try..catch block throws a thread termination exception. > Perhaps Response.Redirect does as well. To fix it, just use > Response.Redirect(url,false) instead, or you can throw an extra chunk > between your try and catch blocks: > > catch (System.Threading.ThreadAbortException ex) > {//Do nothing } > > > -- > breitak67 database is offline or not? |
My System Specs![]() |
| | #5 (permalink) |
| Vista Business x64 | Re: What's wring with this try-catch block? You try to connect to it - if it fails, you inform the user you can't get to the database. You can catch specific error types and check the error details in your try.catch block. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| After wring CD appears blank | Vista hardware & devices | |||
| Is try-catch block a way to prevent a crash? | .NET General | |||
| Catch-all | PowerShell | |||
| How to TRY and CATCH | PowerShell | |||
| I Catch VI | Vista hardware & devices | |||