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:
- Use .NET Core (C#) to query an Azure SQL database.
- Other Azure SQL Database that are nearby the preceding article in the table of contents, about other languages. For instance, see Use PHP to query an Azure SQL database.
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.
Downloads and installs
The following article is devoted to the download and install various SQL connection drivers, for use by programming languages:
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.
|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.|
|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 (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 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 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.|
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.|
With Node.js you can connect to SQL Server from Windows, Linux, or Mac. The root of our Node.js documentation is here.
|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++
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.
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.
|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.|
You can use PHP to interact with SQL Server. The root of our PHP documentation is here.
|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.|
You can use Python to interact with SQL Server.
|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.|
|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.|
You can use Ruby to interact with SQL Server. The root of our Ruby documentation is here.
|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.|
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:
- How to install Microsoft SQL Server
- How to download and install tools and drivers.
- How to make any necessary configurations, as appropriate for your chosen operating system.
- How to compile the provided source code.
- How to run the program.
Next are a couple approximate outlines of the detail provided on the website:
Java on Ubuntu:
- 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
- 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
- Make your Java app up to 100x faster
- Step 3.1 Create a Java app to demonstrate Columnstore indexes
Python on Windows:
- 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
- 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
- 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:
Choose an operating system:
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
- Developer hub for Azure
- Azure for .NET developers
- Azure for Java developers
- Azure for Node.js developers
- Azure for Python developers
- Create a PHP web app in Azure