ADO.Net questions Flashcards

1
Q

What is ADO .NET ?

A

-ADO.NET is the abbreviation for ActiveX Data Object. It is a part of the .NET Framework by Microsoft that provides a set of classes that can be used to handle data interaction with data sources such as databases
- We can use ADO.NET to connect to these data sources and retrieve, handle, and update the data that is stored.

-Sai Krishna C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the provider objects present in ADO. Net Framework
- Sai Krishna C

A

A .NET Framework data provider is used for connecting to a database, executing commands, and retrieving results. Those results are either processed directly, placed in a DataSet in order to be used.
-Connection: Establishes a connection to a specific data source.
-Command: Executes a command against a data source.
-DataReader: Reads a forward-only, read-only stream of data from a data source.
-DataAdapter: Populates a DataSet and resolves updates with the data source.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you define the Dataset structure?
- Bhargav Bhat

A

In ADO.NET, a dataset is an in-memory representation of data that is retrieved from a database or other data source. It consists of a collection of Datatable objects that contain the actual data, as well as information about the structure of the data, such as column names and data types.

We need to define the Dataset structure to ensure the integrity and accuracy of the data that is stored and manipulated in the Dataset. By defining the schema, we can enforce constraints on the data, ensure that the relationships between the tables are correct, and make it easier to retrieve and manipulate the data in a consistent and reliable way.

  • Bhargav Bhat
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the methods of DataSet?
- Bhargav Bhat

A

It is used in disconnected architecture. It represents records in the form of a Database table format. It stores records of one or more tables.

Methods of DataSet:

AcceptChanges(): This method saves changes that are made with records in a Dataset.

Clear(): This method clears all rows from Dataset.

Clone(): The clone method copies the structure of Dataset. This means it copies only schema not full records of DataSet.

Copy(): It copies the whole records with the structure of DataSet.

RejectChanges(): This method discards changes which are made with DataSet and set the DataSet to the previous stage (which was at first).

HasChanges(): This method returns a boolean value to show whether the record of the Dataset has changed or not. It returns true if any changes have been made and false if no other changes made.

GetChanges(): This method keeps a copy of those record, which is changed or modified.

  • Bhargav Bhat
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the architectures followed by Ado.net?
_Aman Shankar

A

The architecture followed by Ado.net for the connectivity with the database is categorized into two modes:-

  • Connected Architecture
    As the name suggests, connected architecture refers to the fact that the connection is established for the full time between the database and application.
  • Disconnected Architecture
    Disconnected architecture refers to the mode of architecture in Ado.net where the connectivity between the database and application is not maintained for the full time. There is no need to establish a connection for the full-time because DataSet acts as temporary storage.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Difference between Connected and Disconnected architecture.
_Aman Shankar

A

Connected Architecture

  • It is connection-oriented.
  • In this, we mainly use the object of the DataReader class.
  • Connected methods give a faster performance.
  • Connected can hold the data of a single table.
  • Connected architecture is forward-only and read-only.
  • Data Reader can’t persist the data.
  • It is Read-only, we can’t update the data.

Disconnected Architecture

  • It is disconnection oriented.
  • In this, we mainly use the object of the SqlDataAdapter and DataSet classes.
  • Disconnected gets low in speed and performance.
  • Disconnected can hold multiple tables of data.
  • The dataset can persist the data
  • We can update the data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what and why we use Data Adapter?
-Siva Billudu

A

Data Adapter will acts as a Bridge between Data Set and database. This data Adapter object is used to read the data from database and bind that data to dataset. Data Adapter is a disconnected oriented architecture.

Data Adapter is a part of the ADO.NET Data Provider. Data Adapter provides the communication between the Dataset and the database. We can use the Data Adapter in combination with the Data Set Object. Data Adapter provides this combination by mapping Fill method, which changes the data in the Data Set to match the data in the database and Update, which changes the data in the database to match the data in the Data Set.

The Data Adapter can perform Select , Insert , Update and Delete SQL operations in the Data Source.

syntax:
SqlDataAdapter sda = new SqlDataAdapter(string query,connection string);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the several execution methods of ADO.NET?
-syed sohail

A

Following are the execute methods of a ADO.NET command object:

Execute Scalar: This method returns a single value from the result get from the execution of SQL query.
For example like : MAX,MIN,AVERAGE,COUNT.
Execute Non Query: This method execute the DML SQL query like insert, update, delete and returns the number of rows affected.
Execute Reader: This method helps us to read the data when we execute the select command and stores it in a data reader object which is a forward-only result set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Connection Pooling in ADO.NET? - Cibi Sharan

A

Connection Pooling is a technique where a database connection is reused instead of creating a new connection every time an operation is performed. This can reduce overhead involved and improve performance.

To enable connection pooling in ADO.NET, you can set the Pooling attribute to true in the connection string. By default, connection pooling is enabled in ADO.NET.

Eg: string connectionString = “Data Source=serverName;Initial Catalog=databaseName;User ID=userName;Password=password;Pooling=True;”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What and Why we use Data Reader?

–Siva Billudu

A

Data Reader is used to read the data from the database and it is a stream-based,read only and forward only connection oriented architecture during fetch the data from database.

The Data Reader cannot be created directly from code, they can created only by calling the Execute Reader method of a Command Object.A Connection Object can contain only one Data Reader at a time and the connection in the Data Reader remains open.

syntax:
SqlDataReader r=sqlcmd.ExecuteReader();
DataReader.read();

The Read() method in the Data Reader is used to read the rows from Data Reader and it always moves forward to a new valid row, if any row exist .Data Reader will fetch the data very fast when compared with dataset.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what are the steps for disconnected architecture in ADO.NET ?
-syed sohail

A
  1. create sql connection object and pass connection string as parameter .
    2.open the connection
    3.create the adapter object and pass the query to be executed and the connection object
    4.create the dataset object
    5.fill the data adapter result in to the dataset
    6.we can perform any data manipulation operations on the dataset
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are some Connection Pooling attributes?
- Cibi Sharan

A

Some of the connection pooling attributes are :

  1. Connection Lifetime - Length of time after which a connection is destroyed. By default, it is 0, which is maximum.
  2. Connection Reset - Specifies whether connection is reset when removed from pooling. Default is true.
  3. Max Pool Size - Maximum number of connections allowed in pool. Default is 100.
  4. Min Pool Size - Minimum number of connections allowed in pool. Default is 0.
  5. Pooling - If true, connection is taken from the appropriate pool. By default, true.

Cibi Sharan

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what are some of the important namespaces available in ADO.NET?

-Mounika B

A

There are some important namespaces available in ADO.NET are:
=>All data-related classes reside in the
System. Data namespace which can be found in the System.Data.dll assembly and it’s secondary namespaces are:

*. System.Data.SqlClient (SQL Server)
*. System.Data.OledbClient (Excel, MS access)
*. System.Data.OracledbClient (oracle)
*. System.Data.PostgresClient (postgres)
*. Microsoft.Data.Odbc : This can be used to connect a Microsoft Access database to an external data source such as Microsoft SQL Server

*. System.Data.Common: This allows you to Map the table names and columns names in the Data Set Using DataColumnMapping and DataTableMapping classes.

*.System.Data.SqlTypes: It provides the Data types with the same semantics and precision as the data types in SQL Server database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the use of Transaction in ADO.NET?

-Mounika B

A

Transaction in ADO.NET is used when you want to bind multiple tasks together so that they execute as a single unit of work

=>ADO.NET supports single-database transactions as well as distributed transactions.
=>Single-database transaction model is implemented using the underlying .NET managed providers for Transaction and Connection classes from the System.Data namespace.
=>Distributed transaction model is implemented using classes in the namespace System.Transactions.

What is the Use of Transaction?
=>To keep the data consistent while we access the data using ADO.NET.
=>Ensures that all operations within the work unit are completed successfully

EX:
public class Transaction
{
static void Main(string[] args)
{
string Connectionstring = (connection string);
SqlConnection con = new
SqlConnection(Connectionstring);
con.Open();
SqlTransaction transaction= con.BeginTransaction();
try
{
SqlCommand cmd1 = new SqlCommand(“select * from student”, con, transaction);
cmd1.ExecuteNonQuery();
SqlCommand cmd2 = new SqlCommand(“select * from student”,con,transaction);
cmd2.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception ex) {
transaction.Rollback();
Console.WriteLine(“Transaction failed”,ex.Message);
}
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is data binding in ADO.NET?

-Yugaraj
A

Data binding in ADO.NET is the process through which user interface (UI) controls of a client application are configured to update or fetch data from data sources like a database or XML document. Using data binding, the user will be able to bind values to the particular control.
Simple data binding: It is the process of binding the control with only one value in the dataset.

Complex data binding: It is the method of binding the component with the Database. The controls can be a Dropdown list, GridView, or combo box.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why Stored Procedure is used in ADO.NET?

-Yugaraj

A

The reasons for using Stored Procedures in ADO.NET are

For improved performance
For security reasons
Easier to use and maintain
Lesser Network Traffic
Execution time is less

16
Q

Explain about ExecuteScalar() in ADO.NET.

-Dhanush

A

A single value from the first row and first column of the ResultSet will be returned by ExecuteScalar() method on query execution.

If the ResultSet is having multiple rows or columns, all those rows and columns will be ignored except the first row and first column. If the ResultSet is empty, this function will return NULL.

The best situation to use ExecuteScalar() method is when we are using functions such as COUNT(), SUM(), etc., as it uses only a few resources compared to the ExecuteReader() method.

17
Q

What are the methods of DataSet?

-Dhanush

A

It is used in disconnected architecture. It represent records in the form of Database table (Row and Column) format. It stores record of one or more tables.

AcceptChanges(): This method saves changes which are made with records in a DataSet.

Clear(): This method clears (removes) all rows from DataSet.

Clone(): The clone method copy the structure of DataSet. Means it copy only schema not full records of DataSet.

Copy(): It copies the whole records with structure of DataSet.

GetChanges(): This method keep copy of those record, which is changed or modified.