BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TADOConnection.Close does not work

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Steve Bailey
Guest





PostPosted: Sun Apr 22, 2007 10:55 pm    Post subject: TADOConnection.Close does not work Reply with quote



I have a TADOConnection on a DataModule connecting to a database using the
Microsoft OLE DB Provider for ODBC Drivers (MSDASQL.1).

When I my application executes ADOConnection1.Close and I watch it with ODBC
trace it is apparent that there is no SQLDisconnect command sent to the
database.

Looking in DB.pas I see:

procedure TCustomConnection.Close;
begin
SetConnected(False);
end;

procedure TCustomConnection.SetConnected(Value: Boolean);
begin
if (csReading in ComponentState) and Value then
FStreamedConnected := True else
begin
if Value = GetConnected then Exit;
if Value then
begin
if Assigned(BeforeConnect) then BeforeConnect(Self);
DoConnect;
SendConnectEvent(True);
if Assigned(AfterConnect) then AfterConnect(Self);
end else
begin
if Assigned(BeforeDisconnect) then BeforeDisconnect(Self);
SendConnectEvent(False);
DoDisconnect;
if Assigned(AfterDisconnect) then AfterDisconnect(Self);
end;
end;
end;

procedure TCustomConnection.DoDisconnect;
begin
end;

procedure TCustomConnection.SendConnectEvent(Connecting: Boolean);
var
I: Integer;
ConnectEvent: TConnectChangeEvent;
begin
for I := 0 to FClients.Count - 1 do
begin
if FConnectEvents[I] <> nil then
begin
TMethod(ConnectEvent).Code := FConnectEvents[I];
TMethod(ConnectEvent).Data := FClients[I];
ConnectEvent(Self, Connecting);
end;
if TObject(FClients[I]) is TDataset then
TDataSet(FClients[I]).DataEvent(deConnectChange, Integer(Connecting));
end;
end;

TCustomConnection.DoDisconnect is empty. Is that right? Does that explain
why my application appears to do nothing when ADOConnection1.Close is
executed?
Back to top
Brian Bushay TeamB
Guest





PostPosted: Mon Apr 23, 2007 6:09 am    Post subject: Re: TADOConnection.Close does not work Reply with quote



Quote:
TCustomConnection.DoDisconnect is empty. Is that right?
It is there to be consistent with other Database connection components


Quote:
Does that explain
why my application appears to do nothing when ADOConnection1.Close is
executed?
No that you will have to look into how ODBC is set up to use SQL server for an

answer

--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Steve Bailey
Guest





PostPosted: Mon Apr 23, 2007 8:11 am    Post subject: Re: TADOConnection.Close does not work Reply with quote



OK. BTW, my original post asked about TCustomConnection.DoDisconnect being
empty. I should, of course, have looked further than that. DoDisconnect is
a virtual method, overridden by TADOConnection.DoDisconnect, which calls
TADOConnection.ConnectionObject.Close. After that it calls code which, I'm
afraid, is beyond me.

My TADOConnection's Provider is "Microsoft OLE DB Provider for ODBC Drivers
(MSDASQL.1)". One of the first ODBC calls MSDASQL must make is to
initialize the ODBC environment: "SQLAllocHandle". This returns a handle.

Is there any way of getting at this handle through TADOConnection? (If
there is then I can call SQLDisconnect myself.)

"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:5l1o2310vjuudopig2p7718rm2somoavn4 (AT) 4ax (DOT) com...
Quote:

TCustomConnection.DoDisconnect is empty. Is that right?
It is there to be consistent with other Database connection components

Does that explain
why my application appears to do nothing when ADOConnection1.Close is
executed?
No that you will have to look into how ODBC is set up to use SQL server
for an
answer

--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Vitali Kalinin
Guest





PostPosted: Mon Apr 23, 2007 1:20 pm    Post subject: Re: TADOConnection.Close does not work Reply with quote

Most probably you are observing ODBC connection pooling in action. - "When
the application releases the connection, the pool returns S_OK to the user,
simulating a successful disconnection from the database. However, the actual
connection is not released by ODBC but instead waits in the pool. When the
next request for a connection to the database that has the same data source
and user information comes in, it is satisfied from the connection in the
pool rather than by making a full connection to the database."
Back to top
Steve Bailey
Guest





PostPosted: Mon Apr 23, 2007 3:54 pm    Post subject: Re: TADOConnection.Close does not work Reply with quote

Thanks for that, Vitali.

Is there any way I can switch off Connection Pooling (at least temporarily)
from within my application?

"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> wrote in message
news:462c6c55$1 (AT) newsgroups (DOT) borland.com...
Quote:
Most probably you are observing ODBC connection pooling in action. - "When
the application releases the connection, the pool returns S_OK to the
user, simulating a successful disconnection from the database. However,
the actual connection is not released by ODBC but instead waits in the
pool. When the next request for a connection to the database that has the
same data source and user information comes in, it is satisfied from the
connection in the pool rather than by making a full connection to the
database."

Back to top
Steve Bailey
Guest





PostPosted: Mon Apr 23, 2007 3:56 pm    Post subject: Re: TADOConnection.Close does not work Reply with quote

I have just checked and can confirm that Connection Pooling is actually
disabled on my development machine so, unfortunately, it looks like it is
not the cause of my problem.

"Steve Bailey" <sbailey (AT) mutualconsultants (DOT) ltd.uk> wrote in message
news:462c906d (AT) newsgroups (DOT) borland.com...
Quote:
Thanks for that, Vitali.

Is there any way I can switch off Connection Pooling (at least
temporarily) from within my application?

"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> wrote in message
news:462c6c55$1 (AT) newsgroups (DOT) borland.com...
Most probably you are observing ODBC connection pooling in action. -
"When the application releases the connection, the pool returns S_OK to
the user, simulating a successful disconnection from the database.
However, the actual connection is not released by ODBC but instead waits
in the pool. When the next request for a connection to the database that
has the same data source and user information comes in, it is satisfied
from the connection in the pool rather than by making a full connection
to the database."



Back to top
Vitali Kalinin
Guest





PostPosted: Mon Apr 23, 2007 5:56 pm    Post subject: Re: TADOConnection.Close does not work Reply with quote

Have you tried to disable OLE DB pooling also (append yours connection
string with ";OLE DB Services = -2")?
Back to top
Brian Bushay TeamB
Guest





PostPosted: Wed Apr 25, 2007 7:46 am    Post subject: Re: TADOConnection.Close does not work Reply with quote

Quote:
OK. BTW, my original post asked about TCustomConnection.DoDisconnect being
empty. I should, of course, have looked further than that. DoDisconnect is
a virtual method, overridden by TADOConnection.DoDisconnect, which calls
TADOConnection.ConnectionObject.Close. After that it calls code which, I'm
afraid, is beyond me.

My TADOConnection's Provider is "Microsoft OLE DB Provider for ODBC Drivers
(MSDASQL.1)". One of the first ODBC calls MSDASQL must make is to
initialize the ODBC environment: "SQLAllocHandle". This returns a handle.

Is there any way of getting at this handle through TADOConnection? (If
there is then I can call SQLDisconnect myself.)
I don't know of one.


Why do you want to use ODBC for SQL Server when there is a more capable OLE Db
provider for SQL server?
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Steve Zimmelman
Guest





PostPosted: Wed Apr 25, 2007 8:11 am    Post subject: Re: TADOConnection.Close does not work Reply with quote

Try using the SQLOLEDB provider instead of the ODBC version.

-Steve-

"Steve Bailey" <sbailey (AT) mutualconsultants (DOT) ltd.uk> wrote in message
news:462ba194 (AT) newsgroups (DOT) borland.com...
Quote:
I have a TADOConnection on a DataModule connecting to a database using the
Microsoft OLE DB Provider for ODBC Drivers (MSDASQL.1).
Back to top
Steve Bailey
Guest





PostPosted: Thu Apr 26, 2007 8:11 am    Post subject: Re: TADOConnection.Close does not work Reply with quote

Thank you Vitali!

That works nicely. I was not aware of OLE DB pooling.

You are a star!

Steve.

"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> wrote in message
news:462cace9 (AT) newsgroups (DOT) borland.com...
Quote:
Have you tried to disable OLE DB pooling also (append yours connection
string with ";OLE DB Services = -2")?
Back to top
Steve Bailey
Guest





PostPosted: Thu Apr 26, 2007 8:11 am    Post subject: Re: TADOConnection.Close does not work Reply with quote

I never said it was SQL Server. It's actually Mimer SQL Engine 9.2.

ODBC is the best way to connect to it for a Delphi Win32 application.

It makes no difference to TADOConnection and MSDASQL - they just work
together to call the appropriate ODBC SQL functions and they do absolutely
nothing when ADOConnection.Close is called.

If possible, I need some way of forcing them to call SQLDisconnect or some
way of finding out the ODBC Environment handle so I can call SQLDisconnect
manually.

"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:9eft239rje3blbqejsfnqpfrq5i50fjuhn (AT) 4ax (DOT) com...
Quote:
OK. BTW, my original post asked about TCustomConnection.DoDisconnect
being
empty. I should, of course, have looked further than that. DoDisconnect
is
a virtual method, overridden by TADOConnection.DoDisconnect, which calls
TADOConnection.ConnectionObject.Close. After that it calls code which,
I'm
afraid, is beyond me.

My TADOConnection's Provider is "Microsoft OLE DB Provider for ODBC
Drivers
(MSDASQL.1)". One of the first ODBC calls MSDASQL must make is to
initialize the ODBC environment: "SQLAllocHandle". This returns a handle.

Is there any way of getting at this handle through TADOConnection? (If
there is then I can call SQLDisconnect myself.)
I don't know of one.

Why do you want to use ODBC for SQL Server when there is a more capable
OLE Db
provider for SQL server?
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.