Board index » delphi » Connection with SQL Server during initialzation?

Connection with SQL Server during initialzation?

To make a connection with ADO I must by creating it give the TComponent. But
the problem is that during the initialization part I don't have it.
How can I solve this problem?

Thank you!

 

Re:Connection with SQL Server during initialzation?


Quote
> To make a connection with ADO I must by creating it give the
TComponent. But
> the problem is that during the initialization part I don't have it.
> How can I solve this problem?

Is this what you want?

unit MyUnit;

uses
  ADODB;

const
  Con: TADOConnection = nil;

implementation

initialization

  Con := TADOConnection.Create(nil);
  Con.ConnectionString := <Some connection string>;
  Con.Connected := True;

finalization

  FreeAndNil(Con);

end;

Re:Connection with SQL Server during initialzation?


Don't see how you can your form hasn't been created yet and so none of
it's components. Personally I'd do this in the FormCreate or FormShow
events. Or better yet in a separate Login Form.

Re:Connection with SQL Server during initialzation?


Quote
In article <3ca961d7_1@dnews>, Stasa Jerinic wrote:
> To make a connection with ADO I must by creating it give the TComponent. But
> the problem is that during the initialization part I don't have it.
> How can I solve this problem?

Put the component on a datamodule, remove the datamodule from the autocreate
list, create it in code in your units Initialization section, using an Owner
of Nil. Destroy it in the finalization section.

Be warned: any exceptions caused during this process or when opening the ADO
connection will likely *not* be trapped by the Application object, instead the
app will die a silent death with a run-time error.

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Re:Connection with SQL Server during initialzation?


Thank you!

"Peter Below (TeamB)" <100113.1...@compuXXserve.com> schrieb im Newsbeitrag
news:VA.000086fe.00b7b57f@antispam.compuserve.com...

Quote
> In article <3ca961d7_1@dnews>, Stasa Jerinic wrote:
> > To make a connection with ADO I must by creating it give the TComponent.
But
> > the problem is that during the initialization part I don't have it.
> > How can I solve this problem?

> Put the component on a datamodule, remove the datamodule from the
autocreate
> list, create it in code in your units Initialization section, using an
Owner
> of Nil. Destroy it in the finalization section.

> Be warned: any exceptions caused during this process or when opening the
ADO
> connection will likely *not* be trapped by the Application object, instead
the
> app will die a silent death with a run-time error.

> --
> Peter Below (TeamB)
> Use the newsgroup archives :
> http://www.mers.com/searchsite.html
> http://www.tamaracka.com/search.htm
> http://groups.google.com
> http://www.prolix.be

Other Threads