.NET Framework Data Provider for SQL Server
This .NET Framework Class Library is provided by Microsoft.
The class library is contained in the file System.Data.dll.
The class library is contained in the file System.Data.dll.
Coding
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
C# code sample
VB.NET code sample
Imports System.Data.SqlClient
Dim myConnection As SqlConnection = New SqlConnection()
myConnection.ConnectionString = myConnectionString
myConnection.Open()
' execute queries, etc
myConnection.Close()
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();
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.
A 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.
This is the number one to use if you want your .NET application or website to connect to an SQL Server.
A 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 link missing
The .NET Framework Data Provider for SQL Server installation package download link is missing. Please provide info and contribute to the community by email to
Connection Strings
Additional info or comments on this class library? Want to submit content?