Page 1 of 1

MyConnection

Posted: Tue 15 Aug 2006 02:54
by Goretz
Mushi2.. I want to build an application which is using both online and offline. First I will check whether the connection can be made or not, if successfull the whole application will be using online connection if not it will use offline. But I don't know how to do it, should I use two MyConnection components? and then how to set the whole application to off or online without having two separate applications for online and offline?
Arigato. :wink:

Posted: Wed 16 Aug 2006 01:13
by teunis
You can try the following at run time:
At startup fill in the MyConnection1.Properties for the remote connection

TRY
MyConnection1.Connected:= TRUE;
EXCEPT
// fill in the MyConnection1.Properties for the local database;
Myconnection1.Connected:= TRUE;
END;
Teunis :shock:

Posted: Wed 16 Aug 2006 10:55
by Antaeus
> But I don't know how to do it, should I use two MyConnection components?
If you need to connect to two MySQL Servers simultaneously you should use two instances of TMyConnection component. But if you try to establish connection to remote server and if it fails, you can just change setting of MyConnection component and try to connect to another (e.g. local) server.

> and then how to set the whole application to off or online without
> having two separate applications for online and offline?
If you mean under online mode connecting to remote server and under offline mode connecting to local server, you can use one MyConnection component with different settings for online and for offline mode.

Posted: Thu 17 Aug 2006 03:02
by Goretz
arigato guys! i did as u guys hv suggested

try
dmIRM.CurrentConnection.Connected:=True;
ShowMessage('Online Mode: Connected to HQ Server.');
except
dmIRM.CurrentConnection.Username:='root';
dmIRM.CurrentConnection.Password:='1234';
dmIRM.CurrentConnection.Server:='localserver';
dmIRM.CurrentConnection.Database:='database';
dmIRM.CurrentConnection.Port:=3306;
dmIRM.CurrentConnection.Connected:=True;
ShowMessage('Offline Mode: Using local server.');
end;

but then if i shut down the HQ server, i will not try to connect to the
local database. meaning that it won't go to the except part. y? what can be done? :roll:

Posted: Fri 18 Aug 2006 07:19
by Antaeus
In this case if you try to send any command to server, error will be raised and the following sequence of the events of MyConnection will be called:

Code: Select all

  OnError
  BeforeDisconnect
  AfterDisconnect
You can use these events to reconnect to local server.