• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Why do connections keep opened?

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
rarigo
Asked:
rarigo
  • 9
  • 4
  • 4
  • +3
1 Solution
 
shenqwCommented:
I think you must Free the Form.
0
 
simonetCommented:
What kinda connection is it? TDatabase or TADOConnection?

Alex
0
 
shenqwCommented:
before Close you Form,do this

Table1.Database.Close.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
daniel_cCommented:
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
 
tomer_engelCommented:
after you deactivate it (DB1.close)
now, when you close the form assing all the database events the nil  value;

:x)
0
 
rarigoAuthor Commented:

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
 
VSFCommented:
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
 
rarigoAuthor Commented:
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
 
tomer_engelCommented:
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
 
rarigoAuthor Commented:
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
 
tomer_engelCommented:
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
 
rarigoAuthor Commented:
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
 
rarigoAuthor Commented:
  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
 
tomer_engelCommented:
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
 
rarigoAuthor Commented:
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
 
shenqwCommented:
HaHa,I got it;

try this:


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

0
 
rarigoAuthor Commented:
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
 
rarigoAuthor Commented:
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
 
shenqwCommented:
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
 
rarigoAuthor Commented:
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

Technology Partners: 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!

  • 9
  • 4
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now