Ado.Net Job Interview Questions and Answers
• What Is Ado.net?ADO.NET is a part of the Microsoft .NET Framework. This framework provides the set of classes that deal with data communication between various layers of the software architecture and the database. It provides a continuous access to different data source types such as SQL Server versions 7, 2000, 2005. It also provides connectivity options to data sources through OLE DB and XML. Connectivity may be established with other databases like Oracle, MySQL etc. as well.
ADO.NET has the ability to separate data access mechanisms, data manipulation mechanisms and data connectivity mechanisms.
ADO.NET introduces along with it the disconnected architecture. In a disconnected architecture, data may be stored in a DataSet. It contains providers for connecting to databases, commands for execution and retrieval of results.
The classes for ADO.NET are stored in the DLL System.Data.dll.
• What Is The Meaning Of Object Pooling?
Object pooling is a concept of storing a pool (group) of objects in memory that can be reused later as needed. Whenever, a new object is required to create, an object from the pool can be allocated for this request; thereby, minimizing the object creation. A pool can also refer to a group of connections and threads. Pooling, therefore, helps in minimizing the use of system resources, improves system scalability, and performance.
• Which Properties Are Used To Bind A Datagridview Control?
The DataSource property and the DataMember property are used to bind a DataGridView control.
• What Property Must Be Set And What Method Must Be Called In Your Code To Bind The Data From Some Data Source To The Repeater Control?
You must set the DataSource property and call the DataBind() method.Mention the namespace that is used to include .NET Data Provider for SQL server in .NET code.The System.Data.SqlClient namespace.
• What Is The Difference Between Oledb Provider And Sqlclient?
With respect to usage, there is no difference between OLEDB Provider and SqlClient. The difference lies in their performance. SqlClient is explicitly used to connect your application to SQL server directly, OLEDB Provider is generic for various databases, such as Oracle and Access including SQL Server.Therefore, there will be an overhead which leads to performance degradation.
• How Can We Load Multiple Tables In To Dataset?
DataSet ds=new DataSet();
SqlDataAdapter dap=new SqlDataAdapter(Select * from ,);
dap.Fill(ds,”TableOne”);
SqlDataAdapter dap1=new SqlDataAdapter(Select * from ,);
dap1.Fill(ds,”tableTwo”);
• What Is Partial Class?
A Partial class is a class that can be split into two or more classes. This means that a class can be physically separated into other parts of the class within the same namespace. All the parts must use the partial keyword. All the other classes should also have the same access modifier. At the compile time, all the partial classes will be treated as a single class. Let us list some advantages of having partial classes.
• What Is The Role Of The Dataset Object In Ado.net?
One of the major component of ADO.NET is the DataSet object, which always remains disconnected from the database and reduces the load on the database.
• What Is A Datareader Object?
The DataReader object helps in retrieving the data from a database in a forward-only, read-only mode. The base class for all the DataReader objects is the DbDataReader class.
The DataReader object is returned as a result of calling the ExecuteReader() method of the Command object. The DataReader object enables faster retrieval of data from databases and enhances the performance of .NET applications by providing rapid data access speed. However, it is less preferred as compared to the DataAdapter object because the DataReader object needs an Open connection till it completes reading all the rows of the specified table.
An Open connection to read data from large tables consumes most of the system resources. When multiple client applications simultaneously access a database by using the DataReader object, the performance of data retrieval and other related processes is substantially reduced. In such a case, the database might refuse connections to other .NET applications until other clients free the resources.
• How Can You Identify Whether Or Not Any Changes Are Made To The Dataset Object Since It Was Last Loaded?
The DataSet object provides the following two methods to track down the changes:
The GetChanges() method - Returns the DataSet object, which is changed since it was loaded or since the AcceptChanges() method was executed.
The HasChanges() method - Indicates if any changes occurred since the DataSet object was loaded or after a call to the AcceptChanges() method was made.
If you want to revert all changes since the DataSet object was loaded, use the RejectChanges() method.
• What Are The Various Methods Provided By The Dataset Object To Generate Xml?
The various methods provided by the DataSet object to generate XML are:
o ReadXml() - Reads XML document into a DataSet object.
o GetXml() - Returns a string containing an XML document.
o WriteXml() - Writes an XML data to disk.
• What Is Connection Pooling?
Connection pooling refers to the task of grouping database connections in cache to make them reusable because opening new connections every time to a database is a time-consuming process. Therefore, connection pooling enables you to reuse already existing and active database connections, whenever required, and increasing the performance of your application.
You can enable or disable connection pooling in your application by setting the pooling property to either true or false in connection string. By default, it is enabled in an application.
• What Are The Pre-requisites For Connection Pooling?
The prerequisites for connection pooling are as follows:
o There must be multiple processes to share the same connection describing the same parameters and security settings.
o The connection string must be identical.
• What Are The Usages Of The Command Object In Ado.net?
The following are the usages of the Command object in AD0.NET:
The Command object in AD0.NET executes a command against the database and retrieves a DataReader or DataSet object.
o It also executes the INSERT, UPDATE, or DELETE command against the database.
o All the command objects are derived from the DbCommand class.
o The command object is represented by two classes: SqlCommand and OleDbCommand.
o The Command object provides three methods to execute commands on the database:
o The ExecuteNonQuery() method executes a Transact-SQL statement against the connection and returns the number of rows affected.
o The ExecuteScalar() method returns a single value from a database query.
o The ExecuteReader() method returns a result set by using the DataReader object.
• Explain The Architecture Of Ado.net In Brief.
AD0.NET consists of two fundamental components:
o The DataSet, which is disconnected from the data source and does not need to know where the data that it holds is retrieved from.
o The .net data provider, which allows you to connect your application to the data source and execute the SQL commands against it.
The data provider contains the Connection, Command, DataReader, and DataAdapter objects.The Connection object provides connectivity to the database. The Command object provides access to database commands to retrieve and manipulate data in a database. The DataReader object retrieves data from the database in the readonly and forward-only mode. The DataAdapter object uses Command objects to execute SQL commands. The DataAdapter object loads the DataSet object with data and also updates changes that you have made to the data in the DataSet object back to the database.
• Describe The Disconnected Architecture Of Ado.net's Data Access Model?
ADO.NET maintains a disconnected database access model, which means, the application never remains connected constantly to the data source. Any changes and operations done on the data are saved in a local copy (dataset) that acts as a data source. Whenever, the connection to the server is re-established, these changes are sent back to the server, in which these changes are saved in the actual database or data source.
• What Is The Difference Between The Clone() And Copy() Methods Of The Dataset Class?
The Clone() method copies only the structure of a DataSet. The copied structure includes all the relation, constraint, and DataTable schemas used by the DataSet. The Clone() method does not copy the data, which is stored in the DataSet.
The Copy() method copies the structure as well as the data stored in the DataSet.
• What Is The Use Of Dataview?
User-defined view of a table is contained in a DataView. A complete table or a small section of table depending on some criteria can be presented by an object of the DataView class. You can use this class to sort and find data within DataTable.
The DataView class has the following methods:
Find() - Finds a row in a DataView by using sort key value.
FindRows() - Uses the sort key value to match it with the columns of DataRowView objects. It returns an array of all the corresponding objects of DataRowView whose columns match with the sort key value.
AddNew() - Adds a new row to the DataView object.
Delete() - Deletes the specified row from the DataView object according to the specified index.
• What Are The Parameters That Control Most Of Connection Pooling Behaviours?
The parameters that control most of connection pooling behaviors are as follows:
o Connect Timeout
o Max Pool Size
o Min Pool Size
o Pooling
• How Can You Add Or Remove Rows From The Datatable Object Of Dataset?
The DataRowCollection class defines the collection of rows for the DataTable object in a DataSet. The DataTable class provides the NewRow() method to add a new DataRow to DataTable. The NewRow method creates a new row, which implements the same schema as applied to the DataTable. The following are the methods provided by the DataRowCollection object:
Add() - Adds a new row to DataRowCollection.
Remove()- Removes a DataRow object from DataRowCollection.
RemoveAt() - Removes a row whose location is specified by an index number.
• Explain In Brief Dataadapter Class In Ado.net?
The DataAdapter class retrieves data from the database, stores data in a dataset, and reflects the changes made in the dataset to the database. The DataAdapter class acts as an intermediary for all the communication between the database and the DataSet object. The DataAdapter Class is used to fill a DataTable or DataSet Object with data from the database using the Fill() method. The DataAdapter class applies the changes made in dataset to the database by calling the Update() method.
The DataAdapter class provides four properties that represent the database command:
SelectCommand, InsertCommand, DeleteCommand, and UpdateCommand.
• What Are Different Layers Of Ado.net?
There are three different layers of ADO.Net:
o Presentation Layer
o Business Logic Layer
o Database Access Layer
• What Are The Data Providers In Ado.net?
Following are the Data Providers used in ADO.Net:.
o MS SQL Server.
o OLEDB.
o ODBC.
• What Are The Uses Of Stored Procedure?
Following are uses of Stored Procedure:
o Improved Performance.
o Easy to use and maintain.
o Security.
o Less time and effort taken to execute.
o Less Network traffic.
• What Is The Default Time Out For Sql Command.commandtimeout Property?
The default timeout of Sqlcommand. CommandTimeout property is 30 Seconds.
• What Are The Classes In System.data.common Namespace?
There are two classes involved in System.Data.Common Nameapce:
o DataColumnMapping.
o DataTableMapping.
• What Is Linq?
Language Integrated Query or LINQ provides programmers and testers to query data and it uses strongly type’s queries and results.
• What Are Typed And Untyped Dataset?
Typed datasets use explicit names and data types for their members but untyped dataset uses table and columns for their members.
• How To Stop Running Thread?
Thread.Abort() function stops the thread execution at any time.
• Which Method Is Used To Sort The Data In Ado.net?
Sort() method of GridViewControl is used to sort the data in a datatable.
• Which Object Is Used To Add Relationship Between Two Datatables?
DataRelation object is used to add relationship between two or more datatable objects.
• Which Is The Best Method To Get Two Values From The Database?
ExecuteNonQuery is the best method to get two values from the database.
• What Are All The Classes That Are Available In System.data Namespace?
Following are the classes that are available in System.Data Namespace:
o Dataset.
o DataTable.
o DataColumn.
o DataRow.
o DataRelation.
o Constraint.
• What Are All Components Of Ado.net Data Provider?
Following are the components of ADO.Net Data provider:
Connection object – Represents connection to the Database
Command object – Used to execute stored procedure and command on Database
ExecuteNonQuery – Executes command but doesn’t return any value
ExecuteScalar – Executes and returns single value
ExecuteReader – Executes and returns result set
DataReader – Forward and read only recordset
DataAdapter – This acts as a bridge between database and a dataset.
• What Are The Differences Between Oledb And Sqlclient Providers?
OLEDB provider is used to access any database and provides flexibility of changing the database at any time. SQLClient provider is used to access only SQL Server database but it provides excellent performance than OLEDB provider while connecting with SQL Server database.
• What Are The Different Execute Methods Of Ado.net?
Following are different execute methods of ADO.Net command object:
ExecuteScalar – Returns single value from the dataset
ExecutenonQuery – Returns resultset from dataset and it has multiple values
ExecuteReader – Forwardonly resultset
ExecuteXMLReader – Build XMLReader object from a SQL Query
• What Are All The Commands Used With Data Adapter?
DataAdapter is used to retrieve data from a data source .Insertcommand, UpdateCommand and DeleteCommand are the commands object used in DataAdapter to manage update on the database.
• What Are All The Different Methods Under Sql Command?
There are different methods under SqlCommand and they are:
Cancel – Cancel the query
CreateParameter – returns SQL Parameter
ExecuteNonQuery – Executes and does not return result set
ExecuteReader – executes and returns data in DataReader
ExecuteScalar – Executes and returns single value
ExecuteXmlReader – Executes and return data in XMLDataReader object
ResetCommandTimeout – Reset Timeout property
• What Is The Difference Between Dataset.clone And Dataset.copy?
Dataset.clone object copies structure of the dataset including schemas, relations and constraints. This will not copy data in the table.
Dataset.copy – Copies both structure and data from the table.
• What Is The Difference Between Command And Commandbuilder Object?
Command is used to execute all kind of queries like DML and DDL. DML is nothing but Insert, Update and Delete. DDL are like Create and drop tables.
Command Builder object is used to build and execute DML queries like Create and Drop Tables.
• Is It Possible To Load Multiple Tables In A Dataset?
Yes, it is possible to load multiple tables in a single dataset.
• Which Provider Is Used To Connect Ms Access, Oracle, Etc?
OLEDB Provider and ODBC Provider are used to connect to MS Access and Oracle. Oracle Data Provider is also used to connect exclusively for oracle database.
• Do We Use Stored Procedure In Ado.net?
Yes, stored procedures are used in ADO.Net and it can be used for common repetitive functions.
• What Are The Methods Of Xml Dataset Object?
There are various methods of XML dataset object:
GetXml() – Get XML data in a Dataset as a single string.
GetXmlSchema() – Get XSD Schema in a Dataset as a single string.
ReadXml() – Reads XML data from a file.
ReadXmlSchema() – Reads XML schema from a file.
WriteXml() – Writes the contents of Dataset to a file.
WriteXmlSchema() – Writes XSD Schema into a file.
• What Are All The Different Authentication Techniques Used To Connect To Ms Sql Server?
SQL Server should authenticate before performing any activity in the database. There are two types of authentication:
Windows Authentication – Use authentication using Windows domain accounts only.
SQL Server and Windows Authentication Mode – Authentication provided with the combination of both Windows and SQL Server Authentication.
No comments:
Post a Comment