Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close all connection on exit

Status
Not open for further replies.

kadara

Programmer
Mar 2, 2012
26
DE
Hi,

I'm relative new in vb.net programming, so I have some questions.
I have an application that connects to an oracle server to retrieve some records from tables.
Everything is working well. But I would prevent some problems.
Is there a possibility to close all recordsets and the connection to the oracle server, if the computer on which the application is running, is in the LogOff/ShutDown procedure (and the application was not closed), or, for some reason the application is stop working properly (stop responding)?
 
I have a little different approach to this problem (closing connections to Oracle when application dies or user shuts down running application):
At night when the Oracle is being backed-up, all connections get closed by Oracle. Nobody should be connected to Oracle at this time anyway.(At this time we also unlock any locked records)

This way may work for you if you have similar situation.

If your users can access Oracle 24/7, that’s not the approach I would use.


Have fun.

---- Andy
 

As far as closing connections when the application closing, if you explicitly close all connections as soon as they are no longer in use, this should not be an issue.

Dim conn As OracleConnection

Try

conn = New OracleConnection("connection string")

'do some stuff with the connection

Catch ex As Exception

'handle the error

Finally

If conn.State = ConnectionState.Open Then conn.Close()

conn.Dispose()

GC.Collect()

End Try


Proper error handling is important, as it can prevent most crashes and provide a way to gracefully close connections and such when there is a problem. This should take care of all your connections, so that when the program closes there are none open.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top