MSDN Documentation

Data Connections in Windows Programming

Establishing a reliable connection to data sources is a core task when developing Windows applications. This guide covers the most common technologies, best practices, and sample code for connecting to databases and other data providers using the Windows API, OLE DB, and ADO.NET.

Overview
APIs
Connection Strings
Sample Code

What Is a Data Connection?

A data connection is a set of parameters that describe how an application accesses a data source. It typically includes the provider type, server address, authentication credentials, and other options.

Primary APIs

APILanguageTypical Use
OLE DBC/C++Low‑level, high‑performance database access.
ODBCC/C++, .NETStandardized cross‑platform connectivity.
ADO.NETC# / VB.NETManaged, object‑oriented data access.
WinRT Data APIsC++/CX, C#, JavaScriptUniversal Windows Platform (UWP) apps.

Typical Connection String Patterns

Provider=SQLOLEDB;Data Source=SERVERNAME;Initial Catalog=MyDatabase;Integrated Security=SSPI;
Server=SERVERNAME;Database=MyDatabase;Trusted_Connection=True;
Data Source=MySQLite.db;Version=3;Read Only=False;

For a full list, see Connection Strings Reference.

Sample: Connecting with ADO.NET (C#)

using System;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        var connectionString = @"Server=SERVERNAME;Database=MyDatabase;Trusted_Connection=True;";
        using (var connection = new SqlConnection(connectionString))
        {
            connection.Open();
            Console.WriteLine("Connected to {0}", connection.DataSource);
            // Execute commands...
        }
    }
}

Compile with csc Program.cs and run.