J
James Radke
Hello,
I am attempting to use the proper Try/Catch technique when accessing my
Microsoft SQL server database and have a question...
If I use something similar to the following:
Try
set up SQL connection
open the SQL connection
execute SQL query
Catch
Throw
Finally
close the SQL connection
set the SQL connection object to nothing
end try
Since I am using a Throw to push the error back up to the calling module, if
the execute query causes the issue I am thinking that the throw causes an
immediate stop to the sub - is this correct? so, wouldn't I really want to
also close the connection (after checking if it is open, of course) also
just prior to the throw statement as follows?
Catch ex as exception
if SQL connection open
close SQL connection
end if
set the SQL connection object to nothing
throw ex
Finally ....
Wouldn't this ensure that all resources are freed up/closed correctly?
Every example I have found does not do this, but instead simply closes the
SQL connection in the finally block - am I missing something?
Thanks!
Jim
I am attempting to use the proper Try/Catch technique when accessing my
Microsoft SQL server database and have a question...
If I use something similar to the following:
Try
set up SQL connection
open the SQL connection
execute SQL query
Catch
Throw
Finally
close the SQL connection
set the SQL connection object to nothing
end try
Since I am using a Throw to push the error back up to the calling module, if
the execute query causes the issue I am thinking that the throw causes an
immediate stop to the sub - is this correct? so, wouldn't I really want to
also close the connection (after checking if it is open, of course) also
just prior to the throw statement as follows?
Catch ex as exception
if SQL connection open
close SQL connection
end if
set the SQL connection object to nothing
throw ex
Finally ....
Wouldn't this ensure that all resources are freed up/closed correctly?
Every example I have found does not do this, but instead simply closes the
SQL connection in the finally block - am I missing something?
Thanks!
Jim