If you know how many clients could connect, just set the number of possible connections that high.

Personally what I would do is have a single module that connects to the database, caches the handle, and returns it. Every other module just asks the single module to give them the appropriate connection, and gets it without worrying about whether a connect just happened or not. Then each module just has to never close it, and not leave any state.

State you ask? Well yes. For instance if you create #tables in Sybase (ie connection-specific temporary tables) you should also delete them when you are done. To be sure that that kind of state is properly cleaned up what you can do is have the functions that create state use ReleaseAction to make sure that the state will be cleaned up appropriately.

Of course that assumes that the authors of the modules can hold to a reasonable standard. To quote Larry Wall, Give people enough rope to hang themselves, and they'll usually figure out how not to, after several successes. It is your decision whether the people writing those modules have had enough successes already...


In reply to Re (tilly) 1: Using DBI handle in several packages by tilly
in thread Using DBI handle in several packages by Beatnik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.