exit the form ?

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

My aim is "when user close the form , Close all the connection "
But .... there is no such method call "closed" in the form
I just test it that "when user click the "close form" button. The
connections still exist in the SQL server
I need to draw a "close button" and close the connection

any better way to do ? thanks a lot
 
My aim is "when user close the form , Close all the connection "
But .... there is no such method call "closed" in the form
I just test it that "when user click the "close form" button. The
connections still exist in the SQL server
I need to draw a "close button" and close the connection

any better way to do ? thanks a lot

Add some code the the event handler for the forms FormClosing or
FormClosed event.
 
My aim is "when user close the form , Close all the connection "
But .... there is no such method call "closed" in the form
I just test it that "when user click the "close form" button. The
connections still exist in the SQL server
I need to draw a "close button" and close the connection

any better way to do ? thanks a lot

Why exactly do you need to keep the connection open until the user
exits?

IMO it is much better to open the connection when it's needed, and
close it immediately after you are finished with it. It depends a lot
upon the type of application, but in my experience many users tend to
start an application, do a task, and then minimize it and forget it
until they need it again. If this is true with your application then
all of these users have a open connection to your database the entire
time tying up system resources unnecessarily

Just something to consider.

Thanks,

Seth Rowe
 
Why exactly do you need to keep the connection open until the user
exits?

IMO it is much better to open the connection when it's needed, and
close it immediately after you are finished with it. It depends a lot
upon the type of application, but in my experience many users tend to
start an application, do a task, and then minimize it and forget it
until they need it again. If this is true with your application then
all of these users have a open connection to your database the entire
time tying up system resources unnecessarily

Better yet, I think is to have a timer that closes the connection
after a certain amount of time (for one project right now, it leave
the connection open for 3 minutes). I've found that with some
applications, opening and closing all the time slows things down quite
a bit, especially if most tasks make use of the database.
 
Agnes said:
My aim is "when user close the form , Close all the connection "
But .... there is no such method call "closed" in the form
I just test it that "when user click the "close form" button. The
connections still exist in the SQL server
I need to draw a "close button" and close the connection

any better way to do ? thanks a lot

I think if you do any reading on the subject of SQL Server open connections
you will see that they are optomized to remain "open". Try this . Write a
small app that has a button which opens the connection and one that closes
the connection. Then do an sp_who on the server to check connections.
Click the open connection and redo the sp_who. Your connection will be
there. Click the close connection (I am assuming you put code to
open/close). Do sp_who again and the connection is still there. Open the
connection and depending on how busy your SQL Server is you will most likely
obtain the "same" connection.

I think you are worrying too much about this since SQL Server handles it.

Lloyd Sheen
 
Back
Top