Beginning Asp.net 4.5 in Vb by Matthew MacDonald

Beginning Asp.net 4.5 in Vb by Matthew MacDonald

Author:Matthew MacDonald [MacDonald, Matthew]
Language: eng
Format: epub
Tags: Computers, Programming Languages, Programming, Microsoft Programming, C#
ISBN: 9781430243298
Publisher: Apress
Published: 2012-09-26T04:00:00+00:00


In the rest of this chapter, you’ll consider how to write web page code that uses the classes in these namespaces. First you’ll consider the most straightforward approach—direct data access. Then you’ll consider disconnected data access, which allows you to retrieve data in the DataSet and cache it for longer periods of time. Both approaches complement each other, and in many web applications you’ll use a combination of the two.

Using Direct Data Access

The most straightforward way to interact with a database is to use direct data access. When you use direct data access, you’re in charge of building an SQL command (like the ones you considered earlier in this chapter) and executing it. You use commands to query, insert, update, and delete information.

When you query data with direct data access, you don’t keep a copy of the information in memory. Instead, you work with it for a brief period of time while the database connection is open, and then close the connection as soon as possible. This is different from disconnected data access, where you keep a copy of the data in the DataSet object so you can work with it after the database connection has been closed.

The direct data model is well suited to ASP.NET web pages, which don’t need to keep a copy of their data in memory for long periods of time. Remember, an ASP.NET web page is loaded when the page is requested and shut down as soon as the response is returned to the user. That means a page typically has a lifetime of only a few seconds (if that).

Note Although ASP.NET web pages don’t need to store data in memory for ordinary data management tasks, they just might use this technique to optimize performance. For example, you could get the product catalog from a database once, and keep that data in memory on the web server so you can reuse it when someone else requests the same page. This technique is called caching, and you’ll learn to use it in Chapter 23.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.