.NET Framework Data Provider for SQL Server

This .NET Framework Class Library is provided by Microsoft. The main functionality of the class library is contained in the file System.Data.dll.

Add a reference to the assembly System.Data and include the System.Data.SqlClient namespace. Instantiate a new SqlConnection connection object. Set the connection string and open the connection.

VB.NET code sample
Imports System.Data.SqlClient
Dim myConnection As SqlConnection = New SqlConnection()
myConnection.ConnectionString = myConnectionString
myConnection.Open()
' execute queries, etc
myConnection.Close()
C# code sample
using System.Data.SqlClient;
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
// execute queries, etc
myConnection.Close();

Description

The .NET Framework Data Provider for SQL Server uses its own protocol to communicate with SQL Server. It is lightweight and performs well because it is optimized to access a SQL Server directly without adding an OLE DB or Open Database Connectivity (ODBC) layer.

This is the number one to use if you want your .NET application or website to connect to an SQL Server.

An SqlConnection object represents a unique session to a SQL Server data source. With a client/server database system, it is equivalent to a network connection to the server. SqlConnection is used together with SqlDataAdapter and SqlCommand to increase performance when connecting to a Microsoft SQL Server database.

When you create an instance of SqlConnection, all properties are set to their initial values.

If the SqlConnection goes out of scope, it won't be closed. Therefore, you must explicitly close the connection by calling Close or Dispose. Close and Dispose are functionally equivalent. If the connection pooling value Pooling is set to true or yes, the underlying connection is returned back to the connection pool. On the other hand, if Pooling is set to false or no, the underlying connection to the server is actually closed.

To ensure that connections are always closed, open the connection inside of a using block. Doing so ensures that the connection is automatically closed when the code exits the block.

More info about this class library can be found at the Microsoft product page.

Download

There is no '.NET Framework Data Provider for SQL Server' installation package to download. (if you know about an installation package URL you can contribute to the community by submitting the info to us through this message form)

Connection Strings

The .NET Framework Data Provider for SQL Server class library can be used to connect to the following data sources by using the following connection string references:

SQL ServerSQL Server 2019SQL Server 2017SQL Server 2016SQL Server 2014SQL Server 2012SQL Server 2008SQL Server 2005SQL Server 2000SQL Server 7.0Azure SQL Database