Introduction To ADO.NET

In this article, I explain the basic details of ADO.NET.
 

ADO.NET

 
ADO stands for Active Data Object and ADO.NET is a set of .NET libraries for ADO.
 

What ADO.NET is

 
ADO.NET is a collection of managed libraries used by .Net applications for data source communication using a driver or provider. 
 
ADO.NET provides libraries for datasource communication under the following namespaces.
  1. system.Data
  2. system.Data.OleDb
  3. system.Data.SqlClient
  4. system.Data.OracleClient
  5. system.Data.Odbc
Let's see the details of all these namespaces.
 
1. System.Data
 
This namespace is used for holding and managing data on a client machine.
 
This namespace contains the following set of classes:
  1. DataSet
  2. DataTable
  3. DataRow
  4. DataView
  5. DataColoum
  6. DataRelation
2. System.Data.OleDb
 
This namespace can communicate with any Data Sourcem like files, databases, indexing servers, and so on using the “OleDb” Provider.
 
3. System.Data.SqlClient
 
This namespace can communicate with “SQL Server” DataBase only using SqlClient Providers.
 
4. System.Data.OracleClient
 
This namespace can communicate with an “Oracle” DataBase only using OracleClient Providers.
 
5. System.Data.ODBC
 
This namespace contains the same set of classes as the following:
  1. Connection
  2. command
  3. DataReader
  4. DataAdaptar
  5. CommandBuilder
  6. Parameter
Note
 
Here each class is referred to by prefixing with their namespace before the class name to discriminate between each other as in the following:
  1. OleDbConnection: OledbCommand
  2. SqlConnection: SqlCommand
  3. OracleConnection: OracleCommand

Performance Operations on a DataSource

 
Each and every operation we perform on a data source involves the following 3 steps:
  1. Establishing a connection with a DataSource.
  2. Sending a request as an SQL Statement.
  3. Capturing results by the data Source.
1. Establishing a Connection
 
Connecting is a collection of attributes that are used for connecting with the data source. Those are:
  1. Provider
  2. Data Source
  3. User Id and Password
  4. Database or Initial Catalog
  5. Trusted Connection or Integrated Security
  6. DSN
1. Provider
 
As explained earlier, a provider is required for connecting with any data source where we use a different provider for each data source.
 
For example:
  1. Oracle: MsdOra  
  2. SqlClient: SqlOledb.  
  3. Microsoft Access or Excel: Microsoft jet OleDb 4.0  
  4. Microsoft Indexing Server: Msidx. 
2. DataSource
 
It is the name of the target machine to which we want to correct. This is optional when the data is on the local machine.
 
3. User id and password
 
Since databases are secured places for storing data, to connect with them we require a valid user name and password.
 
Oracle: scott/tiger
SQL Server: sa/<pwd>.
 
For SQL Server the default user name is “sa” and the password is that which we provide at the time of installation of SQL Server.
 
4. DataBase Or Initial Catalog
 
These attributes are used when connecting with SQL Server to specify the name of the database that we want to connect with.
 
5. Trusted-connection or Integrated Security
 
These attributes are also used when connecting with SQL Server only to specify that we want to use Windows Authentication.
 
6. DSN
 
This attribute is used when connecting with data sources using ODBC Drivers.
 
For example:
  1. “provider =sqldb;userid=sa;password =<pwd>;DataBase=<DBname>;[DataSource=<Server>]” 

Members of the Connection Class

 
1. Open( )
 
Open a connection with the data source.
 
2. Close( )
 
Close the connection that is open.
 
3. State
 
Get the status of the connection.
 
4. ConnectionString
 
Gets or sets a connection string associated with the connection object.
 
I hope you understand the basic concepts related to ADO.NET.
 
If you want to learn more then visit my blog:
 
Dotnetbyabhipatil


Similar Articles