Homepage for client programming to Microsoft SQL Server

Welcome to our homepage about client programming to interact with Microsoft SQL Server, and with Azure SQL Database in the cloud. This article provides the following information:

  • Lists and describes the available language and driver combinations.
    • Information is given for the operating systems of Linux (Ubuntu and others), MacOS, and Windows.
  • Provides links to the detailed documentation for each combination.
  • Displays the areas and subareas of the hierarchical documentation for certain languages, where appropriate.

Azure SQL Database

In any given language, the code that connects to SQL Server is almost identical to the code for connecting to Azure SQL Database.

For details about the connection strings for connecting to Azure SQL Database, see:

Build-an-app webpages

Our Build-an-app webpages present code examples, along with configuration information, in an alternative format. For more information, see later in this article the section labeled Build-an-app website.

Languages and drivers for client programs

In the following table, each language image is a link to detail about using the language with SQL Server. Each link jumps to a later section in this article.

     
  C# logo   ORM Entity Framework, of .NET Framework   Java logo
  Node.js logo   ODBC for C++
cpp-big-plus
  PHP logo
  Python logo   Ruby logo   ...
   

Downloads and installs

The following article is devoted to the download and install various SQL connection drivers, for use by programming languages:

C# logo C# using ADO.NET

The .NET managed languages, such as C# and Visual Basic, are the most common users of ADO.NET. ADO.NET is a casual name for a subset of .NET Framework classes.

Code examples

Proof of concept connecting to SQL using ADO.NET A small code example focused on connecting and querying SQL Server.
Connect resiliently to SQL with ADO.NET Retry logic in a code example, because connections can occasionally experience moments of connectivity loss.

Retry logic applies well to connections maintained through the internet into any cloud database, such as to Azure SQL Database.
Azure SQL Database: Demonstration of how to use .NET Core on Windows/Linux/macOS to create a C# program, to connect and query Azure SQL Database example.
Build-an-app: C#, ADO.NET, Windows Configuration information, along with code examples.
 

Documentation

C# using ADO.NET Root of our documentation.
Namespace: System.Data A set of classes used for ADO.NET.
Namespace: System.Data.SqlClient The set of classes that are most directly the center of ADO.NET.
 

Entity Framework logo Entity Framework (EF) with C#

Entity Framework (EF) provides Object-Relational Mapping (ORM). ORM makes it easier for your Object-Oriented Programming (OOP) source code to manipulate data that was retrieved from a relational SQL database.

EF has direct or indirect relationships with the following technologies:

  • .NET Framework
  • LINQ to SQL, or LINQ to Entities
  • Language syntax enhancements, such as the => operator in C#.
  • Handy programs that generate source code for classes which map to the tables in your SQL database. For instance, EdmGen.exe.

Original EF, and new EF

The start page for Entity Framework introduces EF with a description similar to the following:

  • Entity Framework is an object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. It eliminates the need for most of the data-access source code that developers usually need to write.

Entity Framework is a name shared by two separate source code branches. One EF branch is older, and its source code can now be maintained by the public. The other EF is new. The two EFs are described next:

EF 6.x Microsoft first released EF in August 2008. In March 2015 Microsoft announced that EF 6.x was the final version that Microsoft would develop. Microsoft released the source code into the public domain.

Initially EF was part of .NET Framework. But EF 6.x was removed from .NET Framework.

EF 6.x source code on Github, in repository aspnet/EntityFramework6
EF Core Microsoft released the newly developed EF Core in June 2016. EF Core is designed for better flexibility and portability. EF Core can run on operating systems beyond just Microsoft Windows. And EF Core can interact with databases beyond just Microsoft SQL Server and other relational databases.

C# code examples:
Getting Started with Entity Framework Core
Getting started with EF Core on .NET Framework with an Existing Database
 

EF and related technologies are powerful, and are a lot to learn for the developer who wants to master the entire area.

 

Java logo Java and JDBC

Microsoft provides a Java Database Connectivity (JDBC) driver for use with SQL Server (or with Azure SQL Database, of course). It is a Type 4 JDBC driver, and it provides database connectivity through the standard JDBC application program interfaces (APIs).

Code examples

Code examples Code examples that teach about data types, result sets, and large data.
Connection URL Sample Describes how to use a connection URL to connect to SQL Server. Then use it to use an SQL statement to retrieve data.
Data Source Sample Describes how to use a data source to connect to SQL Server. Then use a stored procedure to retrieve data.
Use Java to query an Azure SQL database Azure SQL Database example.
Create Java apps using SQL Server on Ubuntu Configuration information, along with code examples.
 

Documentation

The JDBC documentation includes the following major areas:

Java Database Connectivity (JDBC) Root of our JDBC documentation.
Reference Interfaces, classes, and members.
Programming Guide for JDBC SQL Driver Configuration information, along with code examples.
 

Node.js logo Node.js

With Node.js you can connect to SQL Server from Windows, Linux, or Mac. The root of our Node.js documentation is here.

The Node.js connection driver for SQL Server is implemented in JavaScript. The driver uses the TDS protocol, which is supported by all modern versions of SQL Server. The driver is an open source project, available on Github.

Code examples

Proof of concept connecting to SQL using Node.js Bare bones source code for connecting to SQL Server, and executing a query.
Azure SQL database: Use Node.js to query Example for Azure SQL Database in the cloud.
Create Node.js apps to use SQL Server on macOS Configuration information, along with code examples.
 

ODBC for C++

ODBC logo cpp-big-plus

Open database connectivity (ODBC) was developed in the 1990s, and it predates .NET Framework. ODBC is designed to be independent of any particular database system, and independent of operating system.

Over the years numerous ODBC drivers have been created and released by groups within and outside of Microsoft. The range of drivers involve several client programming languages. The list of data targets goes well beyond SQL Server.

Some other connectivity drivers use ODBC internally.

Code example

Documentation outline

The ODBC content in this section focuses on accessing either SQL Server or Azure SQL Database, from C++. The following table lists an approximate outline of the major documentation for ODBC.

Area Subarea Description
ODBC for C++ Root of our documentation.
Linux-Mac   Information about using ODBC on the Linux or MacOS operating systems.
Windows   Information about using ODBC on the Windows operating system.
Administration   The administrative tool for managing ODBC data sources.
Microsoft   Various ODBC drivers that are created and provided by Microsoft.
Conceptual and reference   Conceptual information about the ODBC interface, in addition to traditional reference.
  " Appendixes State transition tables, ODBC cursor library, and more.
  " Develop app Functions, handles, and much more.
  " Develop driver How to develop your own ODBC driver, if you have a specialized data source.
  " Install ODBC installation, subkeys, and more.
  " Syntax APIs for setup, installer, translation, and data access.
   

PHP logo PHP

You can use PHP to interact with SQL Server. The root of our Node.js documentation is here.

Code examples

Proof of concept connecting to SQL using PHP A small code example focused on connecting and querying SQL Server.
Connect resiliently to SQL with PHP Retry logic in a code example, because connections through the Internet and the cloud can occasionally experience moments of connectivity loss.
Azure SQL database: Use PHP to query Azure SQL Database example.
Create PHP apps to use SQL Server on RHEL Configuration information, along with code examples.
 

Python logo Python

You can use Python to interact with SQL Server.

Code examples

Proof of concept connecting to SQL with Python using pyodbc A small code example focused on connecting and querying SQL Server.
Azure SQL database: Use Python to query Azure SQL Database example.
Create PHP apps to use SQL Server on SLES Configuration information, along with code examples.
 

Documentation

Area Description
Python to SQL Server Root of our documentation.
pymssql driver Microsoft does not maintain or test the pymssql driver.

The pymssql connection driver is a simple interface to SQL databases, for use in Python programs. Pymssql builds on top of FreeTDS to provide a Python DB-API (PEP-249) interface to Microsoft SQL Server.
pyodbc driver The pyodbc connection driver is an open source Python module that makes accessing ODBC databases simple. It implements the DB API 2.0 specification, but is packed with even more Pythonic convenience.
 

Ruby logo Ruby

You can use Ruby to interact with SQL Server. The root of our Ruby documentation is here.

Code examples

Proof of concept connecting to SQL with Ruby A small code example focused on connecting and querying SQL Server.
Azure SQL database: Use Ruby to query Azure SQL Database example.
Create Ruby apps to use SQL Server on MacOS Configuration information, along with code examples.
 

Build-an-app website, for SQL client development

On our Build-an-app webpages you can choose from a long list of programming languages for connecting to SQL Server. And your client program can run a variety of operating systems.

Build-an-app emphasizes simplicity and completeness for the developer who is just getting started. The steps explain the following tasks:

  1. How to install Microsoft SQL Server
  2. How to download and install tools and drivers.
  3. How to make any necessary configurations, as appropriate for your chosen operating system.
  4. How to compile the provided source code.
  5. How to run the program.

Next are a couple approximate outlines of the detail provided on the website:

Java on Ubuntu:

  1. Set up your environment
    • Step 1.1 Install SQL Server
    • Step 1.2 Install Java
    • Step 1.3 Install the Java Development Kit (JDK)
    • Step 1.4 Install Maven
  2. Create Java application with SQL Server
    • Step 2.1 Create a Java app that connects to SQL Server and executes queries
    • Step 2.2 Create a Java app that connects to SQL Server using the popular framework Hibernate
  3. Make your Java app up to 100x faster
    • Step 3.1 Create a Java app to demonstrate Columnstore indexes

Python on Windows:

  1. Set up your environment
    • Step 1.1 Install SQL Server
    • Step 1.2 Install Python
    • Step 1.3 Install the ODBC Driver and SQL Command Line Utility for SQL Server
  2. Create Python application with SQL Server
    • Step 2.1 Install the Python driver for SQL Server
    • Step 2.2 Create a database for your application
    • Step 2.3 Create a Python app that connects to SQL Server and executes queries
  3. Make your Python app up to 100x faster
    • Step 3.1 Create a new table with 5 million using sqlcmd
    • Step 3.2 Create a Python app that queries this table and measures the time taken
    • Step 3.3 Measure how long it takes to run the query
    • Step 3.4 Add a columnstore index to your table
    • Step 3.5 Measure how long it takes to run the query with a columnstore index

The following screenshots give you an idea of what our SQL development documentation website looks like.

Choose a language:

SQL Dev website, get started

 

Choose an operating system:

SQL Dev website, Java Ubuntu

 

Other development

This section provides links about other development options. These include using these same languages for Azure development in general. The information goes beyond targeting just Azure SQL Database and Microsoft SQL Server.

Developer hub for Azure

Other languages