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.
- system.Data
- system.Data.OleDb
- system.Data.SqlClient
- system.Data.OracleClient
- 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:
- DataSet
- DataTable
- DataRow
- DataView
- DataColoum
- 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:
- Connection
- command
- DataReader
- DataAdaptar
- CommandBuilder
- 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:
- OleDbConnection: OledbCommand
- SqlConnection: SqlCommand
- OracleConnection: OracleCommand
Performance Operations on a DataSource
Each and every operation we perform on a data source involves the following 3 steps:
- Establishing a connection with a DataSource.
- Sending a request as an SQL Statement.
- 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:
- Provider
- Data Source
- User Id and Password
- Database or Initial Catalog
- Trusted Connection or Integrated Security
- 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:
- Oracle: MsdOra
- SqlClient: SqlOledb.
- Microsoft Access or Excel: Microsoft jet OleDb 4.0
- 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:
- “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