Coffeehouse Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Database connections in ASP.NET pages

Back to Forum: Coffeehouse
  • User profile image
    W3bbo

    'lo

    When working with databases, I know that its best to batch all transactions into a single operation and execute it in a single go.

    ...but how do you work this into ASP.NET pages with dozens of User and Custom controls that need to get their own data from the database?

    ...should I pass a SqlConnection object (created and opened by the Page object) to each control or should each control open and close its own connection?

  • User profile image
    Cairo

    I think letting the View reach directly into the Model is almost always a bad idea. Can you work it so that your view is supplied the data it needs, rather than needing to fetch it itself? That would let you grab all the data at once, making it more efficient as well.

  • User profile image
    Maurits

    W3bbo wrote:
    ...should I pass a SqlConnection object (created and opened by the Page object) to each control or should each control open and close its own connection?


    The first one.

    But if you have connection pooling turned on it makes little difference.

    Try connecting the SQL Server Profiler tool to the target SQL server, and experiment.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.