MSDN Documentation

Microsoft Developer Network

ADO.NET Overview

ADO.NET is a set of .NET Framework classes that expose data access services to the .NET programmer. ADO.NET provides a rich set of components for creating distributed applications that efficiently and securely manage data from multiple data sources. It is an integral part of the .NET Framework, enabling developers to build applications that interact with databases, XML files, and other data sources.

Key takeaway: ADO.NET is the .NET data access technology, facilitating interaction with various data sources.

Core Components

ADO.NET consists of two main parts:

Data Access Architecture

ADO.NET follows a two-tier and N-tier programming model. In a two-tier model, the client application communicates directly with the data source. In an N-tier model, middle tiers handle data access logic, providing greater scalability and security.

Connected vs. Disconnected Data Access

ADO.NET supports both connected and disconnected data access patterns:

  • Connected Data Access: This pattern uses a Connection object to establish a persistent connection to the data source. Data is retrieved and manipulated directly through this connection using DataReader objects. This is efficient for read-only scenarios or when performing operations that require an active connection.
  • Disconnected Data Access: This pattern involves retrieving data from the data source and storing it in a DataSet. The connection to the data source is then closed. Data manipulation occurs on the DataSet in memory. When changes need to be persisted, a connection is re-established to update the data source. This is ideal for applications that need to work with data offline or across multiple network boundaries.

Key ADO.NET Objects

Understanding the fundamental ADO.NET objects is crucial for effective data access:

This overview provides a foundational understanding of ADO.NET. Further sections will delve deeper into each of these components and their usage in various data access scenarios.

// Example: Connecting to a SQL Server database
using System;
using System.Data.SqlClient;

public class Example
{
    public static void Main(string[] args)
    {
        string connectionString = "Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;";
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            try
            {
                connection.Open();
                Console.WriteLine("Connection opened successfully!");
                // Perform database operations here
            }
            catch (SqlException ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
    }
}