ASP.NET Databound controls and connection pools --> How does it work?

Discussion in 'ASP .Net' started by Tom, Sep 12, 2007.

  1. Tom

    Tom Guest

    I try to do the following:

    Generate a pooled connection in a web application. I use the following code:

    In my Global.asax.cs

    protected void Application_Start(object sender, EventArgs e)
    {
    //Creating a global pooled connection object
    ConnectionStringSettings DBconn =
    ConfigurationManager.ConnectionStrings["MyDatabase"];
    SAConnection _conn = new SAConnection(DBconn.ConnectionString);
    Application.Lock();
    Application["DBConnection"] = (SAConnection)_conn;
    Application.UnLock();
    }

    In the code behind of a web page I have:

    protected void Page_Load(object sender, EventArgs e)
    {
    SAConnection _conn = (SAConnection)Application["DBConnection"];

    string commandString = "Select * from MarkenAm";
    SACommand command = new SACommand(commandString);

    try
    {
    _conn.Open();
    command.Connection = _conn;
    SADataReader reader =
    command.ExecuteReader(CommandBehavior.CloseConnection);
    MarkeDL.DataSource = reader;
    MarkeDL.DataBind();
    }
    finally
    {
    _conn.Close();
    }
    }

    This works fine but I have to write all the code manually. Is there any
    way to tell the designer about my connection pool stored in the
    application scope of my web app?? I like to use the click an point
    programming feature of the designer, but want all my web pages to use
    the same centrally defined connection pool. Is this possible and if so how?

    (I wrote tons of web apps in Java, but I am new to ASP.NET)

    Thanks for your help

    Thomas
     
    Tom, Sep 12, 2007
    #1
    1. Advertising

  2. Tom

    bruce barker Guest

    Re: ASP.NET Databound controls and connection pools --> How doesit work?

    you've coded such that no pooling is effectively used, as you are using
    the same connection for all requests. also as you do not lock the
    connection during use (by sqlcommands), two page requests that try to
    use the connection at the same time will fail.

    you should only keep the connection string in application, and create a
    connection for each request. this will enable pooling to be be used by
    every request.


    -- bruce (sqlwork.com)

    Tom wrote:
    > I try to do the following:
    >
    > Generate a pooled connection in a web application. I use the following
    > code:
    >
    > In my Global.asax.cs
    >
    > protected void Application_Start(object sender, EventArgs e)
    > {
    > //Creating a global pooled connection object
    > ConnectionStringSettings DBconn =
    > ConfigurationManager.ConnectionStrings["MyDatabase"];
    > SAConnection _conn = new SAConnection(DBconn.ConnectionString);
    > Application.Lock();
    > Application["DBConnection"] = (SAConnection)_conn;
    > Application.UnLock();
    > }
    >
    > In the code behind of a web page I have:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > SAConnection _conn = (SAConnection)Application["DBConnection"];
    >
    > string commandString = "Select * from MarkenAm";
    > SACommand command = new SACommand(commandString);
    >
    > try
    > {
    > _conn.Open();
    > command.Connection = _conn;
    > SADataReader reader =
    > command.ExecuteReader(CommandBehavior.CloseConnection);
    > MarkeDL.DataSource = reader;
    > MarkeDL.DataBind();
    > }
    > finally
    > {
    > _conn.Close();
    > }
    > }
    >
    > This works fine but I have to write all the code manually. Is there any
    > way to tell the designer about my connection pool stored in the
    > application scope of my web app?? I like to use the click an point
    > programming feature of the designer, but want all my web pages to use
    > the same centrally defined connection pool. Is this possible and if so how?
    >
    > (I wrote tons of web apps in Java, but I am new to ASP.NET)
    >
    > Thanks for your help
    >
    > Thomas
     
    bruce barker, Sep 12, 2007
    #2
    1. Advertising

  3. Tom

    Tom Guest

    Re: ASP.NET Databound controls and connection pools --> How doesit work?

    Thanks for that input bruce. So does this mean, that ASP is managing the
    pool in the background transparently? In J2EE you have to configure
    connection pools in the container (application server) for every
    application.

    I hope ASP connection pools are also on application context and not on
    page context!

    Tom
    bruce barker schrieb:
    > you've coded such that no pooling is effectively used, as you are using
    > the same connection for all requests. also as you do not lock the
    > connection during use (by sqlcommands), two page requests that try to
    > use the connection at the same time will fail.
    >
    > you should only keep the connection string in application, and create a
    > connection for each request. this will enable pooling to be be used by
    > every request.
    >
    >
    > -- bruce (sqlwork.com)
    >
     
    Tom, Sep 13, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darryl L. Pierce

    Tomcat 4.0, MySQL and connection pools...

    Darryl L. Pierce, Aug 18, 2003, in forum: Java
    Replies:
    0
    Views:
    369
    Darryl L. Pierce
    Aug 18, 2003
  2. marvind
    Replies:
    0
    Views:
    325
    marvind
    Feb 1, 2006
  3. Replies:
    0
    Views:
    490
  4. rodchar
    Replies:
    0
    Views:
    396
    rodchar
    Nov 26, 2007
  5. Manu
    Replies:
    0
    Views:
    170
Loading...

Share This Page