error message “Connection is not defined”
error message “Connection is not defined”
Data Module and error message “Connection is not defined” in Form Create
I have a DataModule with the TMSConnection in autocreate.
In the Data Module i have a TMSQuery1 with a Data Source1.
I have a Form1 that opens then TMSQuery1 in Data Module and call a second form.
In the second form i have a TDBEdit connected at DataSource1 in Data Module with an onChangeEvent that opens another TMSQuery2 in Form2.
When I create a Form2, I receive a message “Connection is not defined” opening TMSQyery2.
The same application works fine in BDE
I tried to solve this problem in 2 way :
1) Before opening Form2 i close TMSQuery1.
2) I move the DataSource1 from DataModule to Form2
I think these solutions are’nt acceptable
Does somebody can tell me why happens with SDAC component and not with BDE ?
Does somebody knows another better solution on this problem ?
Thanks in advance
Matteo
I have a DataModule with the TMSConnection in autocreate.
In the Data Module i have a TMSQuery1 with a Data Source1.
I have a Form1 that opens then TMSQuery1 in Data Module and call a second form.
In the second form i have a TDBEdit connected at DataSource1 in Data Module with an onChangeEvent that opens another TMSQuery2 in Form2.
When I create a Form2, I receive a message “Connection is not defined” opening TMSQyery2.
The same application works fine in BDE
I tried to solve this problem in 2 way :
1) Before opening Form2 i close TMSQuery1.
2) I move the DataSource1 from DataModule to Form2
I think these solutions are’nt acceptable
Does somebody can tell me why happens with SDAC component and not with BDE ?
Does somebody knows another better solution on this problem ?
Thanks in advance
Matteo
this is the Datamodule that contains the databases and is the first autocreate form:
unit Y5DmConn;
interface
uses
SysUtils, Classes, DB, DBAccess, MSAccess;
type
TY5UDmConn = class(TDataModule)
Database: TMSConnection;
dbQTemp: TMSConnection;
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Y5UDmConn: TY5UDmConn;
implementation
uses Y5DynControlUser;
{$R *.dfm}
procedure TY5UDmConn.DataModuleCreate(Sender: TObject);
begin
RTVUsrPswIdysnet(Database);
RTVUsrPswQtemp(dbQTemp);
end;
procedure TY5UDmConn.DataModuleDestroy(Sender: TObject);
begin
Database.Close;
dbQTemp.Close;
end;
------------------------------------------
This is a second DataModule on the auto create that contains TMSQuery and TDataSource and opens the TDatabase:
unit DM;
interface
uses
SysUtils, Classes, DB, MemDS, DBAccess, MSAccess;
type
TUDM = class(TDataModule)
IVA: TMSQuery;
DataSource1: TDataSource;
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
UDM: TUDM;
implementation
uses Y5DmConn;
{$R *.dfm}
procedure TUDM.DataModuleCreate(Sender: TObject);
begin
Y5UDmConn.Database.Open;
end;
end.
-----------------------
This is the MainForm on the autocreate:
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFmMain = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FmMain: TFmMain;
implementation
uses Unit1, DM, Y5DmConn;
{$R *.dfm}
procedure TFmMain.Button1Click(Sender: TObject);
begin
Form1:=TForm1.create(application);
Form1.ShowModal;
end;
procedure TFmMain.FormCreate(Sender: TObject);
begin
UDM.IVA.Open;
end;
end.
--------------------------------------
this is the second Form in the Available Forms:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, MemDS, DBAccess, MSAccess, StdCtrls, Mask, DBCtrls;
type
TForm1 = class(TForm)
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
cli: TMSQuery;
procedure DBEdit1Change(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses DM, Y5DmConn;
{$R *.dfm}
procedure TForm1.DBEdit1Change(Sender: TObject);
begin
CLI.CLOSE;
CLI.OPEN; //Here the error is show!!!'Connection is not Defined'
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ACTION:=CAfREE;
Form1:=nil;
end;
end.
----------------------------
I noticed that if i put the TDatasource in form1 the error does not appear but i can't do this..the TDatasource must be on the DataModule (DM) but it raise the error..
unit Y5DmConn;
interface
uses
SysUtils, Classes, DB, DBAccess, MSAccess;
type
TY5UDmConn = class(TDataModule)
Database: TMSConnection;
dbQTemp: TMSConnection;
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Y5UDmConn: TY5UDmConn;
implementation
uses Y5DynControlUser;
{$R *.dfm}
procedure TY5UDmConn.DataModuleCreate(Sender: TObject);
begin
RTVUsrPswIdysnet(Database);
RTVUsrPswQtemp(dbQTemp);
end;
procedure TY5UDmConn.DataModuleDestroy(Sender: TObject);
begin
Database.Close;
dbQTemp.Close;
end;
------------------------------------------
This is a second DataModule on the auto create that contains TMSQuery and TDataSource and opens the TDatabase:
unit DM;
interface
uses
SysUtils, Classes, DB, MemDS, DBAccess, MSAccess;
type
TUDM = class(TDataModule)
IVA: TMSQuery;
DataSource1: TDataSource;
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
UDM: TUDM;
implementation
uses Y5DmConn;
{$R *.dfm}
procedure TUDM.DataModuleCreate(Sender: TObject);
begin
Y5UDmConn.Database.Open;
end;
end.
-----------------------
This is the MainForm on the autocreate:
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFmMain = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FmMain: TFmMain;
implementation
uses Unit1, DM, Y5DmConn;
{$R *.dfm}
procedure TFmMain.Button1Click(Sender: TObject);
begin
Form1:=TForm1.create(application);
Form1.ShowModal;
end;
procedure TFmMain.FormCreate(Sender: TObject);
begin
UDM.IVA.Open;
end;
end.
--------------------------------------
this is the second Form in the Available Forms:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, MemDS, DBAccess, MSAccess, StdCtrls, Mask, DBCtrls;
type
TForm1 = class(TForm)
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
cli: TMSQuery;
procedure DBEdit1Change(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses DM, Y5DmConn;
{$R *.dfm}
procedure TForm1.DBEdit1Change(Sender: TObject);
begin
CLI.CLOSE;
CLI.OPEN; //Here the error is show!!!'Connection is not Defined'
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ACTION:=CAfREE;
Form1:=nil;
end;
end.
----------------------------
I noticed that if i put the TDatasource in form1 the error does not appear but i can't do this..the TDatasource must be on the DataModule (DM) but it raise the error..
Re: error message “Connection is not defined”
I had the same problem. However mine came from moving the MyConnection from Login form to the DM and not updating the Connection in the tables.
All working now.
All working now.