Redigera

Dela via


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:

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.

Code examples

Example Description
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.

Documentation

Area Description
C# using ADO.NET Root of our documentation.
Namespace: System.Data A set of classes used for ADO.NET.
Namespace: Microsoft.Data.SqlClient The set of classes used for Microsoft .NET Data Provider for SQL Server

C# using Entity Framework

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 Entity Framework, and new Entity Framework

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

  • 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:

Version Description
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). It is a Type 4 JDBC driver, and it provides database connectivity through the standard JDBC application program interfaces (APIs).

Code examples

Example Description
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 a 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.

Documentation

The JDBC documentation includes the following major areas:

Area Description
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

With Node.js you can connect to SQL Server from Windows, Linux, or macOS. 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

Example Description
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.

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.

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-macOS 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.
Conceptual and reference Appendixes State transition tables, ODBC cursor library, and more.
Conceptual and reference Develop app Functions, handles, and much more.
Conceptual and reference Develop driver How to develop your own ODBC driver, if you have a specialized data source.
Conceptual and reference Install ODBC installation, subkeys, and more.
Conceptual and reference Syntax APIs for setup, installer, translation, and data access.

PHP

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

Code examples

Example Description
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.

Python

You can use Python to interact with SQL Server.

Code examples

Example Description
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.

Documentation

Area Description
Python to SQL Server Root of our documentation.
pymssql driver Microsoft doesn't 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

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

Code examples

Example Description
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.

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