Solved

Why do connections keep opened?

Posted on 2000-04-19
20
222 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
  • 9
  • 4
  • 4
  • +3
20 Comments
 
LVL 3

Expert Comment

by:shenqw
Comment Utility
I think you must Free the Form.
0
 
LVL 15

Expert Comment

by:simonet
Comment Utility
What kinda connection is it? TDatabase or TADOConnection?

Alex
0
 
LVL 3

Expert Comment

by:shenqw
Comment Utility
before Close you Form,do this

Table1.Database.Close.
0
 
LVL 7

Expert Comment

by:daniel_c
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:tomer_engel
Comment Utility
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
Comment Utility
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
Comment Utility
  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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now