Board index » delphi » CoInitialize error in NT-service

CoInitialize error in NT-service

Hi,

I'm writting an NT-service using Delphi5 that will store messages comming in via the COM-port in an Access database.
I want to connect to the database using ADO, because I want to avoid installing the BDE on the target machine.

The problem is the I get the infamous "CoInitialize has not been called" error when I try to connect to the database.

The DB connection works from within the Deplhi IDE (can set Connected=True on the TADOConnection object).
Also I added the CoInitialize and CoUninitialize statement to  the service OnCreate and OnDestroy events.
But I still get the same error.

The weird thing is that when I add a TDatabase object and let this object connect to the database before the ADOConnection, it works !!! But like a said, I don't want to use the BDE.

What else can I try ????

Kind regards,
Steven

 

Re:CoInitialize error in NT-service


Try putting ActiveX in your uses clause (just a shot in the dark)

--
Brian Slack
Depicus
http://www.depicus.com
"Wake-On-Lan" and "Remote Shutdown"

---

Quote
"Steven" <steven.drie...@totalfinaelf.com> wrote in message

news:3c3ab38c$1_2@dnews...
Quote

> Hi,

> I'm writting an NT-service using Delphi5 that will store messages comming

in via the COM-port in an Access database.
Quote
> I want to connect to the database using ADO, because I want to avoid

installing the BDE on the target machine.
Quote

> The problem is the I get the infamous "CoInitialize has not been called"

error when I try to connect to the database.
Quote

> The DB connection works from within the Deplhi IDE (can set Connected=True

on the TADOConnection object).
Quote
> Also I added the CoInitialize and CoUninitialize statement to  the service

OnCreate and OnDestroy events.
Quote
> But I still get the same error.

> The weird thing is that when I add a TDatabase object and let this object

connect to the database before the ADOConnection, it works !!! But like a
said, I don't want to use the BDE.
Quote

> What else can I try ????

> Kind regards,
> Steven

Re:CoInitialize error in NT-service


ActiveX is in the uses clause (otherwise it would not compile).
I even call CoInitialize using the statement: ActiveX.CoInitialize(nil);

Just to be sure I use the correct version.

Quote
"Brian Slack" <newsgro...@depicus.com> wrote:
>Try putting ActiveX in your uses clause (just a shot in the dark)

>--
>Brian Slack
>Depicus
>http://www.depicus.com
>"Wake-On-Lan" and "Remote Shutdown"

>---
>"Steven" <steven.drie...@totalfinaelf.com> wrote in message
>news:3c3ab38c$1_2@dnews...

>> Hi,

>> I'm writting an NT-service using Delphi5 that will store messages comming
>in via the COM-port in an Access database.
>> I want to connect to the database using ADO, because I want to avoid
>installing the BDE on the target machine.

>> The problem is the I get the infamous "CoInitialize has not been called"
>error when I try to connect to the database.

>> The DB connection works from within the Deplhi IDE (can set Connected=True
>on the TADOConnection object).
>> Also I added the CoInitialize and CoUninitialize statement to  the service
>OnCreate and OnDestroy events.
>> But I still get the same error.

>> The weird thing is that when I add a TDatabase object and let this object
>connect to the database before the ADOConnection, it works !!! But like a
>said, I don't want to use the BDE.

>> What else can I try ????

>> Kind regards,
>> Steven

Re:CoInitialize error in NT-service


Then my next humble suggestion is remove ActiveX from the uses clause and do
not call Co...

Or create everything ADO dynamically.

--
Brian Slack
Depicus
http://www.depicus.com
"Wake-On-Lan" and "Remote Shutdown"

---

Quote
"Steven" <steven.drie...@totalfinaelf.com> wrote in message

news:3c3abd13$1_1@dnews...
Quote

> ActiveX is in the uses clause (otherwise it would not compile).
> I even call CoInitialize using the statement: ActiveX.CoInitialize(nil);

> Just to be sure I use the correct version.

> "Brian Slack" <newsgro...@depicus.com> wrote:
> >Try putting ActiveX in your uses clause (just a shot in the dark)

> >--
> >Brian Slack
> >Depicus
> >http://www.depicus.com
> >"Wake-On-Lan" and "Remote Shutdown"

> >---
> >"Steven" <steven.drie...@totalfinaelf.com> wrote in message
> >news:3c3ab38c$1_2@dnews...

> >> Hi,

> >> I'm writting an NT-service using Delphi5 that will store messages
comming
> >in via the COM-port in an Access database.
> >> I want to connect to the database using ADO, because I want to avoid
> >installing the BDE on the target machine.

> >> The problem is the I get the infamous "CoInitialize has not been
called"
> >error when I try to connect to the database.

> >> The DB connection works from within the Deplhi IDE (can set
Connected=True
> >on the TADOConnection object).
> >> Also I added the CoInitialize and CoUninitialize statement to  the
service
> >OnCreate and OnDestroy events.
> >> But I still get the same error.

> >> The weird thing is that when I add a TDatabase object and let this
object
> >connect to the database before the ADOConnection, it works !!! But like a
> >said, I don't want to use the BDE.

> >> What else can I try ????

> >> Kind regards,
> >> Steven

Re:CoInitialize error in NT-service


Thanks for the hints. I got it working just by moving
the TADOConnection stuff into the ServiceCreate event.
Don't ask me why it works now.

Quote
"Brian Slack" <newsgro...@depicus.com> wrote:
>Then my next humble suggestion is remove ActiveX from the uses clause and do
>not call Co...

>Or create everything ADO dynamically.

>--
>Brian Slack
>Depicus
>http://www.depicus.com
>"Wake-On-Lan" and "Remote Shutdown"

>---
>"Steven" <steven.drie...@totalfinaelf.com> wrote in message
>news:3c3abd13$1_1@dnews...

>> ActiveX is in the uses clause (otherwise it would not compile).
>> I even call CoInitialize using the statement: ActiveX.CoInitialize(nil);

>> Just to be sure I use the correct version.

>> "Brian Slack" <newsgro...@depicus.com> wrote:
>> >Try putting ActiveX in your uses clause (just a shot in the dark)

>> >--
>> >Brian Slack
>> >Depicus
>> >http://www.depicus.com
>> >"Wake-On-Lan" and "Remote Shutdown"

>> >---
>> >"Steven" <steven.drie...@totalfinaelf.com> wrote in message
>> >news:3c3ab38c$1_2@dnews...

>> >> Hi,

>> >> I'm writting an NT-service using Delphi5 that will store messages
>comming
>> >in via the COM-port in an Access database.
>> >> I want to connect to the database using ADO, because I want to avoid
>> >installing the BDE on the target machine.

>> >> The problem is the I get the infamous "CoInitialize has not been
>called"
>> >error when I try to connect to the database.

>> >> The DB connection works from within the Deplhi IDE (can set
>Connected=True
>> >on the TADOConnection object).
>> >> Also I added the CoInitialize and CoUninitialize statement to  the
>service
>> >OnCreate and OnDestroy events.
>> >> But I still get the same error.

>> >> The weird thing is that when I add a TDatabase object and let this
>object
>> >connect to the database before the ADOConnection, it works !!! But like a
>> >said, I don't want to use the BDE.

>> >> What else can I try ????

>> >> Kind regards,
>> >> Steven

Re:CoInitialize error in NT-service


That reminds me how I did it

I added to CoInitialize in the initialization section

--
Brian Slack
Depicus
http://www.depicus.com
"Wake-On-Lan" and "Remote Shutdown"

---

Quote
"Steven" <steven.drie...@totalfinaelf.com> wrote in message

news:3c3afacb$1_2@dnews...
Quote

> Thanks for the hints. I got it working just by moving
> the TADOConnection stuff into the ServiceCreate event.
> Don't ask me why it works now.

> "Brian Slack" <newsgro...@depicus.com> wrote:
> >Then my next humble suggestion is remove ActiveX from the uses clause and
do
> >not call Co...

> >Or create everything ADO dynamically.

> >--
> >Brian Slack
> >Depicus
> >http://www.depicus.com
> >"Wake-On-Lan" and "Remote Shutdown"

> >---
> >"Steven" <steven.drie...@totalfinaelf.com> wrote in message
> >news:3c3abd13$1_1@dnews...

> >> ActiveX is in the uses clause (otherwise it would not compile).
> >> I even call CoInitialize using the statement:

ActiveX.CoInitialize(nil);

- Show quoted text -

Quote

> >> Just to be sure I use the correct version.

> >> "Brian Slack" <newsgro...@depicus.com> wrote:
> >> >Try putting ActiveX in your uses clause (just a shot in the dark)

> >> >--
> >> >Brian Slack
> >> >Depicus
> >> >http://www.depicus.com
> >> >"Wake-On-Lan" and "Remote Shutdown"

> >> >---
> >> >"Steven" <steven.drie...@totalfinaelf.com> wrote in message
> >> >news:3c3ab38c$1_2@dnews...

> >> >> Hi,

> >> >> I'm writting an NT-service using Delphi5 that will store messages
> >comming
> >> >in via the COM-port in an Access database.
> >> >> I want to connect to the database using ADO, because I want to avoid
> >> >installing the BDE on the target machine.

> >> >> The problem is the I get the infamous "CoInitialize has not been
> >called"
> >> >error when I try to connect to the database.

> >> >> The DB connection works from within the Deplhi IDE (can set
> >Connected=True
> >> >on the TADOConnection object).
> >> >> Also I added the CoInitialize and CoUninitialize statement to  the
> >service
> >> >OnCreate and OnDestroy events.
> >> >> But I still get the same error.

> >> >> The weird thing is that when I add a TDatabase object and let this
> >object
> >> >connect to the database before the ADOConnection, it works !!! But
like a
> >> >said, I don't want to use the BDE.

> >> >> What else can I try ????

> >> >> Kind regards,
> >> >> Steven

Other Threads