Home Server
New Blog Posts: Merging Reports - Part 1 and Part 2

SqlConnection in WebModule.

edited April 2011 in Server
I need to put a TADOConnection component on the WebModule/WebTier. Is this a
problem?
I use a .udl file to set up the connection-string and do this in the
OnCreate event. When is the WebModule created?

Regards,
Terje Syversen

Comments

  • edited April 2011

    Delphi's WebBroker for an ISAPI module will create an instance of the
    WebModule for each web request that is received.

    Yes, you can put a TADOConnection on the webmodule. But realize that
    multiple instances of the webmodule may be created/execute at the same time.
    Therefore the code needs to be thread-safe. Best way to accomplish that is
    to avoid using global resources. I don't know if the .udl file is locked
    when the connection string is read, but if it is, then you need to use a
    TCriticalSection to acquire and release it. To do this, declare a unit level
    variable (just under the implementation section)

    var
    uLock: TCriticalSection;

    Use the Intialization/Finalization to create/destroy it.

    initialization

    uLock := TCriticalSection.Create;

    finalization

    uLock.Free;


    Here is an example of how to ensure only one thread at a time, accesses a
    global resource....

    uLock.Acquire;

    try
    // so something

    finally
    uLock.Release;
    end;




    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2011
    Just found this rbWiki example of implementing thread-safety...

    http://www.digital-metaphors.com/rbWiki/Server/Web_Tier/Execute_Specified_Report


    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.