CoInitialize with IntraWeb

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Sawlmgsj
Posts: 35
Joined: Thu 11 Nov 2004 08:35

CoInitialize with IntraWeb

Post by Sawlmgsj » Wed 14 Jun 2006 14:37

Do you have a code snippet to show the syntax I need to get started with IntraWeb?

I get the message that CoInitialize has not been called, although I have included that as:

CoInitialize(nil);

Where should that go in my code?

Delphi 7 + IntraWeb 7 trial.

Thanks,
Steve.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Thu 15 Jun 2006 08:06

You need to call CoInitialize(nil) from unit ActiveX.pas before first connection. Also do not forget to call CoUnInitialize after work is done.

Sawlmgsj
Posts: 35
Joined: Thu 11 Nov 2004 08:35

Position of CoInitialize

Post by Sawlmgsj » Thu 15 Jun 2006 10:56

Many thanks for you help.
I have written this code snippet and called CoInitialize in the main form create event. Then set my connection string. A grid does populate from the table.


procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
CoInitialize(nil);
myConnection.ConnectString:='Data Source=SERVER;Initial Catalog=Equity;Integrated Security=SSPI';
myConnection.Connected:=True;
MSTable1.Active:=True;
end;


Is this the correct way to do it?
Where should I call CoUnInitialize?

Do I have to do this for every form in my web application?

Thanks,
Steve.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Fri 16 Jun 2006 09:38

You can call CoUnInitialize, for example, in OnDestroy event or in finalization section.
In fact you need to call CoInitialize for each thread before first connection and CoUnInitialize at the end of thread.

Sawlmgsj
Posts: 35
Joined: Thu 11 Nov 2004 08:35

IntaWeb

Post by Sawlmgsj » Fri 16 Jun 2006 13:47

Many thanks for your help.

Steve.

Guest

Post by Guest » Tue 18 Jul 2006 14:42

I found a more elegant solution as the whole problem originated from using Intraweb, I rather get Intraweb to initialise com for me. This sorts it out nicely.

When using your MS SQL DbExpress driver or ADO driver with Intraweb, you must set the ComInitialization property in the ServerController to ‘ciMultiThreaded’.

This will eliminates the "CoInitialize has not been called" error.

Post Reply