Startseite ¦  was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews ¦  sonstiges
kylix ¦  tutorials ¦  online shop ¦  fotos ¦  Add&Win Gewinnspiel


Willkommen Gast. Bitte einloggen oder registrieren.
17.05.2012, 03:26:42
Übersicht Hilfe Suche Einloggen Registrieren

+  SwissDelphiCenter Forum
|-+  German Forums
| |-+  Datenbank Forum
| | |-+  How to reconnect with tAdoConnection (Win-XP)
« vorheriges nächstes »
Seiten: [1] Drucken
Autor Thema: How to reconnect with tAdoConnection (Win-XP)  (Gelesen 2551 mal)
isr123
Newbie
*
Offline Offline

Beiträge: 8


« am: 15.11.2008, 12:15:54 »

Hello all,
Using Delphi 6-Pro+Ado+ Db2.

I use tAdoConnection to connect to database.
After a line break it is impossible to reconnect, we can reconnect only
after the application has been restarted.

Please advise how to fix it.

Many thanks
I. Nemlich   


Gespeichert
grenzgaenger
Global Moderator
Full Member
*****
Offline Offline

Beiträge: 232


« Antworten #1 am: 15.11.2008, 19:59:19 »

hello isr123,

have you created your database component static or dynamically? in the second case you can destroy and recreate the database component...

for your DB2 connection I've no idea, then I dosn't work with this database. but perhaps the idea (above) will help.

kind regards
GG
Gespeichert
isr123
Newbie
*
Offline Offline

Beiträge: 8


« Antworten #2 am: 16.11.2008, 09:02:55 »

Hello GG,

I use static components.
It seems that the problem source is not DB2.

It sounds a good idea to use the components dynamically,
where can I find a sample how to do it.

Many thanks
I. Nemlich
 
Gespeichert
grenzgaenger
Global Moderator
Full Member
*****
Offline Offline

Beiträge: 232


« Antworten #3 am: 16.11.2008, 10:16:55 »

hello isr123,

you have to implement to new methods in your datamodule a connect and a disconnect one.

if you want to break the connection so you destroy the connection object (proc: disconnect), if you go to (re)connect you (re)create the connection object. the disadvantages is, there you can't use the object inspector.

Hope this helps
GG

your data module can now look as follows:

interface

uses
  SysUtils, Classes, adodb;

type
  TDataModule2 = class(TDataModule)
    procedure DataModuleDestroy(Sender: TObject);
  private
    { Private-Deklarationen }
   
  public
    { Public-Deklarationen }
    fConnection: tAdoConnection;
    procedure Disconnect;
    procedure Connect;
  end;

var
  DataModule2: TDataModule2;

implementation

{$R *.dfm}

procedure TDataModule2.Connect;
begin
 Disconnect;
 fConnection := TADOConnection.Create(NIL);
 fConnection.ConnectionString := GetMyConnectionString;
 //other connection settings
 fConnection.Connected := true;
end;

procedure TDataModule2.DataModuleDestroy(Sender: TObject);
begin
 Disconnect;
 inherited;
end;

procedure TDataModule2.Disconnect;
begin
 if fConnection <> NIL then
 begin
  fconnection.Close;
  FreeAndNIL(fConnection);
 end;
end;

end.
Gespeichert
isr123
Newbie
*
Offline Offline

Beiträge: 8


« Antworten #4 am: 16.11.2008, 17:35:25 »

Hi GG,

Your solution works great.

Many thanks
I. Nemlich
Gespeichert
Seiten: [1] Drucken 
« vorheriges nächstes »
Gehe zu:  


Einloggen mit Benutzername, Passwort und Sitzungslänge

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006, Simple Machines LLC Prüfe XHTML 1.0 Prüfe CSS