hi everyone
my doubt is that
iam writing some code with in a try catch block which is connecting to database and bringing data.
intailly connection is opened and execution is started
at a sudden it looses the connection to databse because of some LAN Probelm.
when exception raises and catching that in the catch block.
In Catch block iam checking connection state, if it is closed iam again trying to connect to database.i will try till it is connected to database.
my issue is that when iam connected to database in the catch block i should start execute from the same procedure where i was lose my connection. or the line where i lose the connection.
warm regards
Loading
SokakPosted Apr 27, 2007, 1:34 AM
Typically for database connectivity it is a good idea to only open connections for as long as they are needed, then close them again. This way you might have something like this to allow a data controller to attempt to load an object and retry that attempt if it encounters a connectivity issue:
(Pseudo Code)
Customer myCustomer = null;
int retry = 0;
while (myCustomer == null && retry < 5)
{
try
{
myCustomer = CustomerFactory.CreateCustomer(someCustomerID);
}
catch // catch specific connection exception to retry, otherwise do something else.
{
retry++;
Thread.Sleep(1000); //Optionally wait between retries.
}
}
if (retry == 5)
throw new Exception("Customer could not be loaded.");