Microsoft.SqlClient Namespace

Overview

The Microsoft.SqlClient namespace provides the core classes for accessing Microsoft SQL Server from .NET applications. It contains implementations of Connection, Command, DataReader, Transaction, and other essential objects that enable robust data manipulation and retrieval.

Classes

Getting Started

using Microsoft.Data.SqlClient;

var connectionString = "Server=localhost;Database=SampleDB;Trusted_Connection=True;";
using var connection = new SqlConnection(connectionString);
connection.Open();

var command = new SqlCommand("SELECT TOP 10 * FROM Employees", connection);
using var reader = command.ExecuteReader();
while (reader.Read())
{
    Console.WriteLine($"{reader["Id"]}: {reader["Name"]}");
}
    

Additional Resources