Mention the usage of Connection Object in ADO.NET

Connection object is used to establish a connection between your .NET application and the database used by your application.



If you have to manipulate data from the database using ADO.NET, you have to follow the steps shown below:

Create a connection
Open the Connection
• Create a command object containing the query and assign the same to the connection you have opened
• Execute the Query and use datareader or dataset to read the result of the query
Close the connection

You have to ensure that you close the connection as soon as you finish your tasks related to the database. This makes your application run faster and allows the database to be used by multiple resources of your application.

Two different types of connection object exist in ADO.NET. They are mentioned below:

SqlConnection: Available in the namespace System.Data.SqlClient. It is used to connect to SQL Server database with version 7.0 or higher.
OleDbConnection: Available in the namespace System.Data.OleDb. It is used to connect to all databases using OLE DB providers.

Apart from creating and opening a connection, several other methods exist in a connection object. Methods associated with Connection Object are: BeginTrans, Cancel, Close, CommitTrans, Execute, Open, OpenSchema and RollbackTrans. With these methods, you can manage your transaction and you can even rollback from your current transaction. Connection object also includes several properties, events and collections.

| How do you implement Observer Design Pattern in .NET? | How do you pass data between different Tiers in .NET Architecture? | How is Classic ADO different from ADO.NET? | How is Dataadapter useful in ADO.NET? | How is Datareader different from Dataset in ADO.NET? | How is .NET Application Development different from Traditional Development? | How is HashTable different from ArrayList in .NET? | How is Inheritance achieved in C#? | How is new keyword different from override keyword during inheritance in .NET? | How is String class different from StringBuilder class in .NET? | Illustrate ADO.NET Architecture | Illustrate the importance of Server.Transfer and Response.Redirect in .NET? | Mention the different objects available in Dataset of ADO.NET | Mention the usage of Connection Object in ADO.NET | What are the commonly used methods of Dataadapter in ADO.NET? | What are the different Behavioral Design Patterns that can be used in .NET Architecture? | What are the different Creational Design Patterns that can be used in .NET Architecture? | What are the different Structural Design Patterns that can be used in .NET Architecture? | What are the methods provided by Command Objects in ADO.NET? | What is Internal Access Modifier in C#? |


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.