Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Is there a way disconnect from database

by turumkhan (Novice)
on Jun 28, 2001 at 22:24 UTC ( #92405=categorized question: print w/replies, xml ) Need Help??
Contributed by turumkhan on Jun 28, 2001 at 22:24 UTC
Q&A  > database programming


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
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.
- 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.

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (6)
    As of 2019-09-19 22:58 GMT
    Find Nodes?
      Voting Booth?
      The room is dark, and your next move is ...

      Results (253 votes). Check out past polls.