MyConnection

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Goretz
Posts: 10
Joined: Mon 07 Aug 2006 10:26
Contact:

MyConnection

Post by Goretz » Tue 15 Aug 2006 02:54

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:

teunis
Posts: 48
Joined: Wed 01 Feb 2006 14:15
Location: Curacao

Post by teunis » Wed 16 Aug 2006 01:13

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:

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 16 Aug 2006 10:55

> 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.

Goretz
Posts: 10
Joined: Mon 07 Aug 2006 10:26
Contact:

Post by Goretz » Thu 17 Aug 2006 03:02

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:

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Fri 18 Aug 2006 07:19

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.

Post Reply