The classes that are responsible for working with the database for connecting, retrieving, updating, inserting, and deleting data are referred to as provider classes in the framework. The ADO.NET libraries contain provider classes, which are classes that you can use to transfer data between a data store and the client application. The Microsoft .NET Framework contains the following data access providers: OleDb Odbc SqlServer Oracle
To access a data store, you need a valid, open connection object. The DbConnection class is an abstract class from which the provider-specific connection classes inherit. To create a connection, you must have a valid connection string.DbConnection connection = new SqlConnection();connection.ConnectionString ="Server=.;Database=pubs;Trusted_Connection=true";connection.Open();//do work hereconnection.Close();
Open Database Connectivity (ODBC) is one of the oldertechnologies that the .NET Framework supports, primarilybecause there are still many scenarios in which the .NETFramework is required to connect to older databaseproducts that have ODBC drivers.
Another common, but older, technology that isused to access databases is Object Linking andEmbedding for Databases (OLEDB).
This connection string uses the settings stored in theMyAppData.udl file (the .udl extension stands for universaldata link):FILE NAME=C:Program FilesMyAppMyAppData.udlThis connection string uses the Jet driver, which is theAccess driver, and opens the demo.mdb database file.Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Program FilesmyAppdemo.mdb;Persist Security Info=False
<connectionStrings><add name="PubsData“ providerName="System.Data.SqlClient"connectionString= "Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|PUBS.MDF; IntegratedSecurity=True; User Instance=True"/></connectionStrings>ConnectionStringSettings pubs =ConfigurationManager.ConnectionStrings["PubsData"];DbConnection connection = new SqlConnection(pubs.ConnectionString);
Connection pooling is the process of reusing existing active connections instead of creating new connections when a request is made to the database. It involves the use of a connection manager that is responsible for maintaining a list, or pool, of available connections. When the connection manager receives a request for a new connection, it checks its pool for available connections. If a connection is available, it is returned. If no connections are available, and the maximum pool size has not been reached, a new connection is created and returned. If the maximum pool size has been reached, the connection request is added to the queue and the next available connection is returned, as long as the connection timeout has not been reached.
Connection pooling is controlled by parametersplaced into the connection string. The followingis a list of parameters that affect pooling: Connection Timeout Min Pool Size Max Pool Size Pooling Connection Reset Load Balancing Timeout, Connection Lifetime Enlist
The DbCommand object is used to send one or more Structured Query Language (SQL) statements to the data store. The DbCommand can be any of the following types: Data Manipulation Language (DML) Commands that retrieve, insert, update, or delete data Data Definition Language (DDL) Commands that create tables or other database objects, or modify the database schema Data Control Language (DCL) Commands that grant, deny, or revoke permissions