Board index » delphi » Cannot close ADO connection to detach DB, SQL Server 2000

Cannot close ADO connection to detach DB, SQL Server 2000

To detach a DB I need to close the current ADOConnection first.

For some reason it seems that calling Close or setting Connected to true,
will not close the connection, since sp_Detach fails to detach.
If at this point I use the Enterprise Manager to detach, then it will not
allow this since there is one (1) "Connection using this database".
After some time, a minute or so, this "connection" is gone,
and I can detach.

If I never open the ADOConnection in the first place the attach/detach
procedure works fine.

Is there a delay in closing in closing the connection, inhibiting the
detach?
Is there something else I can be doing wrong?

Thanks,
Anders Johansson

 

Re:Cannot close ADO connection to detach DB, SQL Server 2000


Quote
"Anders Johansson" <anders.johans...@NOSPAMrangeservant.se> wrote in message

news:3d58a88d@dnews...

Quote
> To detach a DB I need to close the current ADOConnection first.

> For some reason it seems that calling Close or setting Connected to true,
> will not close the connection, since sp_Detach fails to detach.
> If at this point I use the Enterprise Manager to detach, then it will not
> allow this since there is one (1) "Connection using this database".
> After some time, a minute or so, this "connection" is gone,
> and I can detach.

> If I never open the ADOConnection in the first place the attach/detach
> procedure works fine.

> Is there a delay in closing in closing the connection, inhibiting the
> detach?

It's probably the automatic pooling of connections that OLE DB does. When
you close the connection, the connection actually remains open for a while,
in case it can be reused. Try adding '; OLE DB Services = -2' to the end of
your connection string to disable this, and see if that helps. For more info
see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmd...

Regards,
Andy Mackie.

Re:Cannot close ADO connection to detach DB, SQL Server 2000


Andy, you solved my problem, again.
Thank you very much.
Anders

"Andy Mackie" <amac...@citynetworks.co.uk> skrev i meddelandet
news:3d58bad0$1@dnews...

Quote
> "Anders Johansson" <anders.johans...@NOSPAMrangeservant.se> wrote in
message
> news:3d58a88d@dnews...
> > To detach a DB I need to close the current ADOConnection first.

> > For some reason it seems that calling Close or setting Connected to
true,
> > will not close the connection, since sp_Detach fails to detach.
> > If at this point I use the Enterprise Manager to detach, then it will
not
> > allow this since there is one (1) "Connection using this database".
> > After some time, a minute or so, this "connection" is gone,
> > and I can detach.

> > If I never open the ADOConnection in the first place the attach/detach
> > procedure works fine.

> > Is there a delay in closing in closing the connection, inhibiting the
> > detach?

> It's probably the automatic pooling of connections that OLE DB does. When
> you close the connection, the connection actually remains open for a
while,
> in case it can be reused. Try adding '; OLE DB Services = -2' to the end
of
> your connection string to disable this, and see if that helps. For more
info
> see

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmd...

- Show quoted text -

Quote
> /pooling2.asp

> Regards,
> Andy Mackie.

Other Threads