Solved

Why do connections keep opened?

Posted on 2000-04-19
20
226 Views
Last Modified: 2010-04-04
Hi Guys,

   I've noticed that every time I activate a table it conects to the database but does not disconect after I deactivate it and close the form.
   How can I drop this conection??

Thank you.

Sinceramente,
Reginaldo

PS. I'm talking about SQL Server 6.5,Delphi 3.0 and BDE 5.01

0
Comment
Question by:rarigo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
  • 4
  • +3
20 Comments
 
LVL 3

Expert Comment

by:shenqw
ID: 2732974
I think you must Free the Form.
0
 
LVL 15

Expert Comment

by:simonet
ID: 2733002
What kinda connection is it? TDatabase or TADOConnection?

Alex
0
 
LVL 3

Expert Comment

by:shenqw
ID: 2733009
before Close you Form,do this

Table1.Database.Close.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:daniel_c
ID: 2733293
Put this in Event FormClose:

<YourDatabaseName>.Connected:= false;

For example:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Db1.Connected:= false;
end;

I assume that you are using TDatabase for connecting to MS SQL 6.5.

If you are using TTable, using this:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Table1.Active:= false;
end;

Hope this help!
0
 
LVL 1

Expert Comment

by:tomer_engel
ID: 2733659
after you deactivate it (DB1.close)
now, when you close the form assing all the database events the nil  value;

:x)
0
 

Author Comment

by:rarigo
ID: 2734303

shenqw: the form is freed but doesn't   work.

daniel c: I can't turn Db1.Connected to false because other tables or queries on other forms still use it. I want to drop the connection of this table I'm deactivating only.

simonet: It is a TDatabase connection.


Sinceramente,
Reginaldo








0
 
LVL 3

Expert Comment

by:VSF
ID: 2734435
Well there is a way but it's not quite professional, if u have 2 form acessing the same file, u could add another table and use the command line
  datamodule1.db1.close;
on the onclose event of each form.
This works if u have a few forms.

ps: u will also have to make the tables syncrhonus, i mean always at the same record (both)
0
 

Author Comment

by:rarigo
ID: 2734606
I've said before that I don't want to close db. If it's not possible to drop this connection that a TABLE created without closing the database please you tell me otherwise I want to be able to close, free, to set active to false anything with this table so as I get only one connection ( the Database one ) as it was before activating a table.
0
 
LVL 1

Expert Comment

by:tomer_engel
ID: 2734681
how d you know the connection is n closed?make sure that:
a) there isn't another form//application isn't using the file(the table file).
b)all the data to the table have been posted before trying to close the connection.
c)try to creae the table at run-time--not dropping the component on the data-moudule/the form
and then try to free it after dropping the connetion -->if after that a connection is still opened --someone else is using the file--if you run the program in the delphi inviorment ,and turns the program abnormaly->with CTRL+F2(or end program from the delphi menu)-->this operation DOESNT close all the connection-'cause it doesn't free all the resources,if this is your situation--don't end your program abnormaly.
0
 

Author Comment

by:rarigo
ID: 2734806
Hi Tomer,

   If you run a query with SP_WHO at ISQL/w it gives you all the existing connections to the database. So I'm watching these connections while the program is running. At the very beggining I have only one connection ( the Database one ) but if I open a form with a table on it a new connection is made to the database and after that even after I closed the form and deactivate and released all I could the connection is still opened.


     
   


0
 
LVL 1

Expert Comment

by:tomer_engel
ID: 2735172
so try my suggestion--try to make it a dynamical table in your code,by the way ,,do you have more "tables" in your application and this is the only one causing you trouble?
0
 

Author Comment

by:rarigo
ID: 2735280
Hi Tomer,

   If you run a query with SP_WHO at ISQL/w it gives you all the existing connections to the database. So I'm watching these connections while the program is running. At the very beggining I have only one connection ( the Database one ) but if I open a form with a table on it a new connection is made to the database and after that even after I closed the form and deactivate and released all I could the connection is still opened.


     
   


0
 

Author Comment

by:rarigo
ID: 2735295
  Strange thing!!! I didn't post that twice.

Tommer: Yes I have more tables. After I noticed that I've change most of them to queries. But there're some that I couldn't change and any of them give me that kinda of problem.
       I'll try to create them at run time and see what happens.
     
     Till there so..

Reginaldo
         
       

0
 
LVL 1

Expert Comment

by:tomer_engel
ID: 2736236
i don't know what delphi version.BDE version you're using,

a)any case try downloading the delphi update pack from inprise site(if you hadn't allready..)

b)try making another application(small one) that contains only the tables and the DB component,,and look if this small app. causes any trouble.

c)as i said earlier--don't stop your program abnormaly-->with CTRL+F2 or end program from the Delphi menu bar--'cause it's leaving the connection open ,,(even if you're shutting down delphi)

0
 

Author Comment

by:rarigo
ID: 2743387
Tomer_engel:
    Nope it didn't help creating the table at run time. It creates another connection to the database by the time you activate it and doesn't drop the same connection when deactivate and close it.
    I'm using SQL Server 6.5, Delphi 3.0 and BDE 5.01.
    No. I'm not "closing" the program abnormally. All these happens as the program is still running. I mean... I open the program.. and check the connections i have just one ( the database one ).... then I open any form with ttables components on it and i have more connections created the i close the form and the code will deactivate and free everything but the connections are still there till i close the application 'cause this will drop the main connection ( the database one ). Get it??

Reginaldo

0
 
LVL 3

Expert Comment

by:shenqw
ID: 2744433
HaHa,I got it;

try this:


procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Table1.Active:=False;
  Table1.DBSession.DropConnections;
end;

0
 

Author Comment

by:rarigo
ID: 2744593
shenqw: I surely wanted to accept your answer but it did not work. Based on your answer i've tried all other variants like Session.KeepConnection := false or Session.Database[1].KeepConnection and nothing of these worked either.

Can you think of something else?


Sinceramente,
Reginaldo
0
 

Author Comment

by:rarigo
ID: 2745006
shenqw: I surely wanted to accept your answer but it did not work. Based on your answer i've tried all other variants like Session.KeepConnection := false or Session.Database[1].KeepConnection and nothing of these worked either.

Can you think of something else?


Sinceramente,
Reginaldo
0
 
LVL 3

Accepted Solution

by:
shenqw earned 150 total points
ID: 2745951
hi rarigo:
  Before my last answer ,I had try it,and it works fine.based on D5+Pack1+SQL 7.0+NT4+SP6.

Here is the help about DropConnections:

Frees all temporary database components associated with a session if they are inactive.

procedure DropConnections;

Description

Use DropConnections to free all temporary database components that are currently inactive. If the KeepConnections property of the session is True (the default), then temporary database components created as needed for the session by Delphi at runtime are not automatically freed when their database connections are closed. DropConnections enables an application to free these components when they are no longer needed.



If you try all way and can't Drop the Connection ,you can set you table1.databasename:=yourdatamodule.database1.databasename.I think that will be ok.
0
 

Author Comment

by:rarigo
ID: 2747268
Hi shenqw,

   I've read that help about DropConnections before and i'm aware that that this the right direction but didn't work for me and worst of all i don't know why.
   But I decided to close this question and give you these points not to solve the problem but to point me the right way.
  Thanks.
  Hope to 'see ya' at next question. hehe


Sinceramente,
Reginaldo
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question