Page 1 of 1

Problem with MSConnection.Connect in Service (TService).

Posted: Tue 08 Sep 2009 14:48
by jabu
Hello,

I use MSConnection in Service (TService). When I set MSConnection.Connected to True in design time then all running ok, but when MSConnection.Connected is False in design time and I use MSConnect.Connect in TService.ServiceExecute event then TService not start and in application log is error "OLE DB error occured. Code 800401F0h. CoInitialize has not been called.."

How is possible to connect MSConnection in runtime in TServiceApplication?

SDAC 4.70.0.50
Delphi 7
NativeClient for SQL2008

jabu

Posted: Wed 09 Sep 2009 07:15
by Dimon
You should not set MSConnection.Connected to True in design time, instead use the following code to connect to SQL server in runtime:

Code: Select all

MSConnection.Connect;

Re: Problem with MSConnection.Connect in Service (TService).

Posted: Tue 15 Sep 2009 16:54
by shincs
jabu wrote:Hello,

I use MSConnection in Service (TService). When I set MSConnection.Connected to True in design time then all running ok, but when MSConnection.Connected is False in design time and I use MSConnect.Connect in TService.ServiceExecute event then TService not start and in application log is error "OLE DB error occured. Code 800401F0h. CoInitialize has not been called.."

How is possible to connect MSConnection in runtime in TServiceApplication?

SDAC 4.70.0.50
Delphi 7
NativeClient for SQL2008

jabu
Try this:

procedure TService.ServiceExecute(Sender: TService);
begin
CoInitializeEx(NIL,COINIT_MULTITHREADED);

..
// your code
..

CoUnInitialize;
end;