Problem with MSConnection.Connect in Service (TService).

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jabu
Posts: 15
Joined: Fri 05 Nov 2004 11:47

Problem with MSConnection.Connect in Service (TService).

Post by jabu » Tue 08 Sep 2009 14:48

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

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 09 Sep 2009 07:15

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;

shincs
Posts: 2
Joined: Wed 02 Jan 2008 10:42

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

Post by shincs » Tue 15 Sep 2009 16:54

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;

Post Reply