The Connection Object
The Connection object is the first component of ADO.NET that you should be looking at. A connection sets a link between a data source and ADO.NET. A Connection object sits between a data source and a DataAdapter (via Command). You need to define a data provider and a data source when you create a connection. With these two, you can also specify the user ID and password depending on the type of data source. Figure 3-3 shows the relationship between a connection, a data source, and a data adapter.
Figure 1: The relationship between connection, data Adapter, and a data source
Connection can also be connected to a Command object to execute SQL queries, which can be used to retrieve, add, update and delete data to a data source. Figure 2 shows the relationship between the Command and Connection objects.
Figure 2: The relationship between the command object and connection object
The Connection object also plays a useful role in creating a transaction. Transactions are stored in transactions objects, and transaction classes have all those nice features for dealing with transactions such as commit and rollback. Figurer 3 shows the relationship between the connection object and transaction.
Figure 3: Creating a transaction from a connection object
Each data provider has a Connection class. Below Table shows the name of various connection classes for data providers.
Table: Data provider connection classes
DATA PROVIDER |
CONNECTION CLASS |
OleDb |
OleDbConnection |
Sql |
SqlConnection |
ODBC |
OdbcConnection |
Conclusion
Hope this article would have helped you in understanding ADO.NET Connection object. See my other articles on the website on ADO.NET.