CJLeit Posted May 22, 2007 Posted May 22, 2007 Hello, I have a database connection that I'm closing in the finally section of my error trapping. The problem is sometimes an error occurs before the connection is open so when it hits the finally the connection.close line causes another error to happen. Is there an easy way to ignore errors in the finally section of my error trapping? Thanks! Quote
Administrators PlausiblyDamp Posted May 22, 2007 Administrators Posted May 22, 2007 You would have to put a try catch block within the finally block if you want to supress errors raised there. It might be easier to check for the likely causes (probably the connection object being null / nothing) and simply don't attempt to close the connection if you haven't got a valid connection. Out of interest what language / version of .Net are you using? C# all versions and VB.Net from version 2.0 have a using keyword that pretty much does what you are after. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
CJLeit Posted May 23, 2007 Author Posted May 23, 2007 Unfortunetly for this project I have to use VS 2003 or else I would try the Using function. Thanks for your reply! Quote
amir100 Posted May 31, 2007 Posted May 31, 2007 I believe it is possible to check the state of the connection before you close that connection. The syntax would likely look like this: If (yourConnection.State = ConnectionState.Open) Then yourConnection.Close() End If Quote Amir Syafrudin
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.