Article
Top 5 .NET Newbie Q and A
ADO.NET
ADO.NET is the data layer of .NET, and it's very good. ADO.NET is (unlike its predecessor technology, ADO) built around a disconnected data architecture. Database connections are "expensive" performance-wise, so ADO.NET only uses data connections briefly. It connects to the database to get data and update data. When it's not completing either of those tasks, the connection is freed up for other pages to use.
Most Web applications spend a large portion of their time simply reading through data and displaying it, and ADO.NET provides a disconnected subset of the data (called a DataSet) for the application while reading and displaying. ADO.NET then updates the database only when the DataSet is altered.
Given all the opening and closing of database connections, this approach has scalability issues, of course. ADO.NET remedies this by pooling connections, i.e. while it looks to your application as if you're creating and destroying connections, you're actually borrowing and returning connections from a pool that ADO.NET manages for you.
Also, ADO.NET offers extremely powerful database abstraction. Remember the earlier example in the ASP.NET section, with the database and the select box?
String myConnectionString = "server=(local)
\MyMSSQLServer;database=myDataBase;User ID=Admin"
SqlConnection myConnection =
new SqlConnection(myConnectionString);
SqlDataAdapter myCommand =
new SqlDataAdapter("SELECT * FROM Guitars", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Guitars");
GuitarSelectBox.DataSource = ds.Tables["Guitars"].DefaultView;
DataBind();
Now, think of the DataSet as a bucket. In this bucket, you have cached versions of all the DB tables your application needs. The SqlDataAdapter can be imagined as a bottle, in which you mix your DB Connection string and your SQL SELECT command. The contents of the SqlDataAdapter-bottle are then poured into the DataSet-bucket, and your application has access to all the tables.
Now, why are the DataSet and DataAdapter separate? Why can't you mix the SQL Connection string and SELECT command directly into the DataSet-bucket? Because you can use several different types of DataAdapters, such as XML DataAdapters, Oracle DataAdapters etc., so that one DataSet can be comprised of several different data sources. So you can essentially make this one DataSet the only object your application needs for data access, even though you might use 4 different RDBMS and 3 XML data sources. Pretty cool, huh?
Caching
.NET automatically caches classes when they are compiled, so that they can be delivered with extremely speed when they are called. But the Framework also offers some other cool types of caching, for instance, output caching. Here, certain parts of dynamically generated Web pages can be stored on the hard drive in static form, so that they can be delivered directly instead of being generated every time. This is so simple to implement that my cat could do it:
<%@ Page language="C#">
<%@ OutputCache Duration="120" VaryByParam="*" %>
<html>
<!-- rest of page goes here -->
This caches the page output for 120 seconds after originally running the page, and saves a separate version of the page for every unique combination of query string values of form variables. You can also use the VaryByParam attribute to let the page to only vary the cache if certain variables defined by you changes. -- MJohansson
.NET also provides cross-platform compatibility.
Cross-platform on Windows only?
It sounds like a contradiction in terms, but I was involved in Visual Basic client/server app a couple of years. We had the server set up and the development PC working well. As we went around the building installing the new app on users' PCs, we encountered problems left and right, most of which were unique to the individual PCs.
Similar to Java, the .NET platform runs as a layer between the basic operating system and your program. Your program isn't running on Windows 98 or 2000 or XP, it's running on a single .NET platform -- this is what makes the multiple languages possible.
In a perfect world, Microsoft would open this up to other non-MS operating systems. Think of it: you could write a program in any language to work with other programs written in any language to run on any computer! - Westmich