Learn ASP.NET 2.0 - SQL Server and ASP.NET
In yesterday's database technology, a program would open a database much like it would open any file and simply retrieve the data that it needed. Today, thing's aren't that simple. The main thing that has changed is networking. In today's networked environment, it's not that unusual for thousands of programs to be hitting against the database at the same time. It's totally impractical for just one of them to have it tied up for longer than a few microseconds.
Microsoft's response is ASP.NET and ADO.NET. The key to understanding it is to understand the two ways to access a database using these technologies: connected and disconnected.
A program that uses connected access to a database connects, works with the data, and quickly disconnects again. Because the database is actually tied up during the connection, connected access is very restricted.
- All data retrieved is "read only" - you can't change it.
- Data is retrieved in a forward-only fashion. You can't read a previous record and you get the data in the order the database provides it to you.
The ADO.NET object used for connected access is the DataReader. A DataReader is great when you only need to read (not delete or change) the information.
Some programmers use the rule of "three G's" when using the DataReader:
- Get in. (Open the database connection.)
- Get the data. (Using a DataReader.)
- Get out. (Close the connection again.)
Disconnected access requires more complex code but it's capable of higher performance applications.
These are the typical steps involved in disconnected access.
- Connect to the database.
- Get a copy of the data.
- Disconnect to free up the database.
- Process the data.
- Reconnect to the database.
- Update the database from the copy.
- Disconnect again.
That's a lot more code than connected access. In the example program that we will write, connected access will be used to keep things simpler.
The primary object used with disconnected access is the DataSet. This is an in-memory object that holds a copy of the data from the database that you can process much like it was the database itself. A DataSet is made up of DataTable objects, that are like the actual tables in the database. You can read, edit, and write to the DataSet just as you would with the database. Because the program isn't working with the actual data in the database, it can do anything without the risk of creating bad data in the database as long as the data is right when the program is ready to be committed back to the database.
Just as in the first lesson, we're going to use VWD to create our website. But this time, we're also going to create a very simple database using SSE and the built in VWD interface into SSE.