Click here to Skip to main content
15,850,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my software I have a connection module which makes a connection to the MySQL database connection. It passed the handle back to the main module. This module then passes the handle to any module that requires database access.

Thats all very well, but if the system is idle for any length of time the connection closes and causes a crash when the next access is attempted.

Apart from good old fashioned 'return' what are my options if one of these low level modules is forced to re establish the connection when it comes to passing the new handle back to the main module so that usage can continue?
Posted
Updated 30-Nov-11 9:53am
v2

1 solution

Hi,

i don't know this solution works for you,

Create one class that holds connection object as lazy loading
like myconn.ExecuteCommand
here ExecuteCommand property is lazy loading when we call, it will create connection with database with myconn object property like connectionstring, sql command etc.

so you can say for every attempt to execute command new connection will be created. if you connection is lost with database it will form new connection at the time of ExecuteCommand.

hope this will help you.

thanks
-amit.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900