FrankPedro
Programmer
- Jul 18, 2012
- 2
Hi Guys
This one baffles me. I'm trying to make my app so that it auto reconnects after the connection has been lost. I have a timer that tries to execute a simple query such as "Select 1". If an exception is thrown I know the connection has been lost. I then handle the situation by trying to close the connection and reopening it. This will keep on going until I can successfully query the database again. The problem is this. When I step through the code when the reconnection is suppose to take place, it keeps on failing and says "login failed for user...". This is after the connection is actually active and I can query the database on the backend. Instead of closing and opening the same conneciton I've even tried to destroy the object and create a new one, with all the same connection properties as defined on the form. But still, when I open the connection it gives the same msg "Login failed for user...". I have made a test application where it actually works. So I don't know why in the actuall app it is holding the connection or something?
Here is the default properties of the connection:
procedure TfrmMainDataMod.ResetConnection;
begin
try
try
if FConnectionString = '' then
FConnectionString := DBCON.ConnectionString;
if assigned(DBCON) then
FreeAndNil(DBCON);
DBCON := TADOConnection.Create(self);
with DBCON do
begin
Close;
Connected := false;
CommandTimeout := 120;
ConnectionString := FConnectionString;
ConnectionTimeout := 120;
ConnectOptions := coConnectUnspecified;
CursorLocation := clUseClient;
IsolationLevel := ilReadUncommitted;
KeepConnection := true;
LoginPrompt := false;
Mode := cmRead;
Provider := 'SQLOLEDB.1';
tag := 0;
Name := 'DBCON';
DefaultDatabase := '';
Open; // this part does not connect successfully, not matter how many times it tries.
end;
except on e:Exception do
MessageDlg(e.message, mtError, [mbOK], 0); // Error msg: Login failed for user
end;
finally
end;
end;
It would be awesome if someone can direct me in the right direction.
Thank you!
This one baffles me. I'm trying to make my app so that it auto reconnects after the connection has been lost. I have a timer that tries to execute a simple query such as "Select 1". If an exception is thrown I know the connection has been lost. I then handle the situation by trying to close the connection and reopening it. This will keep on going until I can successfully query the database again. The problem is this. When I step through the code when the reconnection is suppose to take place, it keeps on failing and says "login failed for user...". This is after the connection is actually active and I can query the database on the backend. Instead of closing and opening the same conneciton I've even tried to destroy the object and create a new one, with all the same connection properties as defined on the form. But still, when I open the connection it gives the same msg "Login failed for user...". I have made a test application where it actually works. So I don't know why in the actuall app it is holding the connection or something?
Here is the default properties of the connection:
procedure TfrmMainDataMod.ResetConnection;
begin
try
try
if FConnectionString = '' then
FConnectionString := DBCON.ConnectionString;
if assigned(DBCON) then
FreeAndNil(DBCON);
DBCON := TADOConnection.Create(self);
with DBCON do
begin
Close;
Connected := false;
CommandTimeout := 120;
ConnectionString := FConnectionString;
ConnectionTimeout := 120;
ConnectOptions := coConnectUnspecified;
CursorLocation := clUseClient;
IsolationLevel := ilReadUncommitted;
KeepConnection := true;
LoginPrompt := false;
Mode := cmRead;
Provider := 'SQLOLEDB.1';
tag := 0;
Name := 'DBCON';
DefaultDatabase := '';
Open; // this part does not connect successfully, not matter how many times it tries.
end;
except on e:Exception do
MessageDlg(e.message, mtError, [mbOK], 0); // Error msg: Login failed for user
end;
finally
end;
end;
It would be awesome if someone can direct me in the right direction.
Thank you!