Contributed by turumkhan
on Jun 28, 2001 at 22:24 UTC
Q&A
> database programming
Description: I am stuck with a very typical problem.... and need help badly.....
The thing is i am using DBI to connect to a database
and at the end of the script i disconnect form the database by
$db_handle->disconect();
but this disconnect happens at the end of script.. Now if something happens and my script is killed before it reaches the end of the script... how to i disconnect form the database. Like i do a CTRL + c on the script that kills the execution but doesnot disconnect from database.... so is there a way for me to disconnect from database when this happens.
thanks
- turum. Answer: Is there a way disconnect from database contributed by mikeB DBI will automatically close open connections at the end of a program, but will complain to let you know you forgot. This happens even with Ctrl-C, as the closing is handled by the connection's DESTROY method, which is invoked by Perl's garbage collection when the program terminates.
A major problem with depending on the automatic close is the variance in handling of open transactions. Some DBD's will commit, while others rollback.
Check out chapter 4 of Programming the Perl DBI (the ORA Cheetah book).
| Answer: Is there a way disconnect from database contributed by Mr. Muskrat In most cases you can use:
END {
$db_handle->disconnect();
}
| Answer: Is there a way disconnect from database contributed by aijin You should set up a signal handler.
$SIG{INT} = \&some_subroutine;
will run the subroutine on a Ctrl-C.
$SIG{INT} = 'IGNORE';
will ignore Ctrl-C and the program will keep running. |
Please (register and) log in if you wish to add an answer
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|