Tuesday, 6 August 2013

ADO.NET Basic interview questions and ansewers

1.    What are the major difference between classic ADO and ADO.NET?
·          In ADO we have record set and in ADO.NET we have Dataset.
·          In recordset we can only have one table. If we want to accommodate more than one tables we need to do inner join and fill the recordset.
·          Dataset can have multiple tables.
·          All data persist in XML as compared to classic ADO where data persisted in Binary format also.
2.    What two classes are used to read data only?
                 Use the SqlDataReader and OleDbDataReader classes to read data in a forward direction only.
3.    What are the two fundamental objects in ADO.NET?
                 There are the two fundamental objects in ADO.NET are :
·          Data reader
·          Data set
4.    What method is used by the Command classes to execute SQL statements that return single values?
                The Execute scalar method executes SQL commands that return single values.
5.    Which namespaces are used for data access?
·          System.Data
·          System.Data.OleDB
·          System.Data.SQLClient
6.    What is the difference between Dataset and Data reader?
·          Data Reader provides forward only and read only access to data, while the Data set objects can hold more than one table from the same data source as well as the relationships between them.
·          Dataset is a disconnected architecture while data reader is connected architecture.
·          Dataset can persist contents while data reader cannot persist contents they are forward only.
7.    What two types of data providers does ADO.NET supply? What determines which one you should use?
                ADO.NET contains the SQL data provider and the OLE DB data provider. Use the sqlDataProvider for
               SQL Server because it's optimized specifically for this database. Use the OLE DB provider for other databases.
8.    What is the use of connection object?
·          They are used to connect a data to a command object.
·          An OleDbconnection object is used with an OLEDB provider.
·          A SqlConnection object uses tabular data services (TDS) with MS SQL Server.

9.    What are basic methods of Data adapter?
                  There are three most commonly used methods of Data adapter :
·          Fill
·          Fill Schema
·          Update

10.  What are the two main types of classes associated with errors that are thrown by ADO.NET classes?
                Objects of type sqlError and oleDbError are thrown by the ADO.NET classes.
11.  What method is used by the Command classes to execute SQL statements that return single values?

                 The Execute scalar method executes SQL commands that return single values.
12.  What is the use of command Object?
              There are used to connect connections object to Data reader or data set.
·          Execute Non Query
·          Execute Reader
·          Execute Scalar

13.  Define Execute Non Query?

                Executes the command defined in the command text property against the connection defined in the
               connection property for a query that does not return any row (Insert, Update or Delete).Returns an
               integer indicating the number of rows affected by the query.
14.  Define Execute Reader?
                Executes the command defined in the command text property against the connection defined in the
               connection property.Returns a reader object that in connected to the resulting row set within the
               database, allowing the rows to be retrieved.
15.  Define Execute Scalar?
                Executes the command defined in the command text property against the column defined in the
               connection property.Returns only single value the first column of the first row of the resulting row set
               any other returned columns and rows are discarded.
16.  What are the benefits of ADO.NET?
                There are so many benefits of ADO.NET are
·          Scalability
·          Data Source Independence
·          Interoperability
·          Strongly Typed Fields
·          Performance
17.  What is the use of Data View?

Data View represents a complete table or can be small of rows depending on some criteria. It is the best used for sorting and finding data with in data table.
18.  What method in the oleDbDataAdapter class populates a dataset with records?
                 The Fill method populates a dataset with records.
19.  What is Dataset Object?

                 Dataset is a disconnected, in-memory representation of data. It can contain multiple data table from
                different database.
20.  What are the various methods provided by the dataset object to generate XML?
                 There are three methods provided by the dataset object to generate XML are :
·          Read XML
·          GET XML
·          Write XML

21.  What is the difference between dataset clone and copy?

                Dataset Clone : It only copies structure does not copy data.
               Dataset Copy : Copies both structure and data.
22.  What two classes are used to open and connect to a database using ADO.NET?
                 Use the sqlconnection and oleDbConnection classes to connect to a database using ADO.NET.
23.  What is the use of Command builder?
   Command builder builds "parameter" objects automatically. Below is a simple code, which uses commands builder to load its parameter objects.

24.  Name some ADO.NET Objects?
·          Connection Object
·          DataReader Object
·          Command Object
·          DataSet Object
·          DataAdapter Object
25.  How can you populate one Dataset object with data from two different physical databases?

                 Use two connection objects and two Adapter objects. Open a connection to both databases, and then fill
              the same Dataset with the two Adapters.
26.  What are the data access namespaces in .NET?
                 The most common data access namespaces :
·          System. Data
·          System.Data.OleDb
·          System.Data.SQLClient
·          System.Data.SQLTypes
·          System.Data.XML
27.  What is the difference between Dataset and Data reader?
                  Data Reader provides forward only and read only access to data, while the Data set objects can hold more
                 than one table from the same data source as well as the relationships between them.
                 Dataset is a disconnected architecture while data reader is connected architecture. Dataset can persist
                Contents   while data reader cannot persist contents they are forward only.
28.  What is the use of data adapter?
                 This object act as a bridge between data store and dataset.
29.  What two classes are used to execute arbitrary SQL commands in a database using ADO.NET?

                  The Sqlcommand and Oledb command classes are used to execute SQL Commands using ADO.NET.
30.  What is the use of connection object in ado.net?
                The ADO Connection Object is used to create an open connection to a data source. Through this connection,
               you can access and manipulate a database.
31.  What is the difference between ADO.Net Dataset and ADO Record set?
                 ADO.Net Dataset you can retrieve data from two databases like oracle and sql server and merge them in
                one dataset with record set this is not possible. All representation of dataset is using XML while record set
                uses com.
                ADO.Net Record set cannot be transmitted on HTTP while dataset can be.

32.  How arc Row states used in ADO.NET?
                 The DataAdapter class uses Rowstates to extract modified, added, or deleted records.
33.  What is dataset object?
                 The dataset provides the basic for disconnected storage and manipulation of relational data. We fill it from
                a data store, work with it while disconnected from that data store, then reconnect and flush changes back
                 to the data store if required.
34.  What is the use of System.Data namespace in ADO.Net?
                System.Data : This contains the basic objects used for accessing and storing relational data such
               as dataset,datatable and data relation.
35.  What is the use of Sytem.Data.OLEDB namespace in ADO.Net?
                 Sytem.Data.OLEDB : It contains the object that we use to connect to a data source. These objects inherit
                the common base classes and to have the same properties, methods and events as the SqlClient equivalents.
36.  What is the use of System.Data.sqlclient namespace in ADO.Net?
                 System.Data.sqlclient : This contains the objects that we use to connect to a data source .
             This can generally provide better performance as it removes some of the intermediate layers required
             by an OLE-DB connection.
37.  What is the use of System. XML namespace in ADO.Net?
                System. XML : This contains the basic objects required to create read, store, write and manipulate
              XML documents according to W3C recommendations.
38.  What is the preferred method for executing SQL commands that contain parameters?
                The preferred method is to use the sqlParameter and oleDbParameter objects, as detailed in the
              section "Using Parameters with the command Object."
39.  What are the two fundamental objects in ADO.NET?
                 There are two fundamental objects in ADO.NET are : 
               Datareader - connected architecture and 
               Dataset - disconnected architecture.
40.  What is the use of command object?
                         This is the responsible object to use stored procedure.
41.   What .NET tools are used to automatically generate XML Schemas and typed datasets?
               Use either Visual Studio or the XSD.exe tool.

42.  What are different types of Commands available with Data Adapter?
                 The SqlDataAdapter are:
·         Select Command
·         Insert Command
·         Delete Command
·         Update  Command
43.  What is the use of data adapter?
                These objects connect one or more command objects to a Dataset object.
              An OleDb Data Adapter object is used with an OLE-DB provider.
              A Sql Data Adapter object uses Tabular Data Services with MS SQL Server.
44.  What is a Dataset?
                A Dataset is an in memory representation of data loaded from any data source.
45.  What method is used by the command classes to execute commands that do not return result sets, such as the SELECT COUNT command?
               The Execute Non Query method executes SQL commands that don't return a result set.
46.  What are good ADO.NET objects to replace the ADO Recordset object?
47.  Why two interfaces can be used to abstract the SQL and OLE DB data providers?

   You can use the IDataReader, IDbCommand, and IDataAdapter classes to abstract the data provider.

48.  What is the difference between "Optimistic" and "Pessimistic" locking?

   In Pessimistic locking when user wants to update data it locks the record and till then no one can update data.
In Optimistic locking multiple users can open the same record for updating, thus increase maximum concurrency.
49.  What is the DataTableCollection?
     An ADO.NET DataSet contains a collection of zero or more tables represented by DataTable objects. The DataTableCollection contains all the DataTable objects in a DataSet.
50.  What providers does Ado.net uses?
            The .NET Framework provides mainly three data providers, they are
·          Microsoft SQL Server
·          OLEDB
·          ODBC

Thursday, 6 June 2013

Good Employees Make Mistakes. Great Leaders Allow Them To.

As a business leader, I found that one of the scariest things to do was to give your people the freedom to make mistakes. While mistakes allow individuals to learn and grow, they can also be very costly to any company. Scared as I was, I knew that truly great leaders found ways to allow their people to take these risks, and I genuinely wanted to be a great leader. I wanted to help my employees to grow. So I set out to discover how to accomplish this without placing my company in jeopardy.
“Courage is not the absence of fear, but rather the judgment that something else is more important than fear.”  Meg Cabot
I quickly discovered that the first step was to determine the areas of the business where a mistake could take place without causing too much damage. I took careful attention to make sure that any areas where we would damage our clients and the trust they had placed in us were off limits for significant risk without serious executive involvement and oversight. I identified other areas where I could feel more comfortable allowing people the freedom to experiment on new and better ways of doing things.
The second step was to communicate to the employees that we were setting an official company policy:  Making any mistake once was OK, so long as it was an honest mistake made while attempting to do what they felt was the right thing. Making any mistake once was OK, but repeating that same mistake a second time was NOT OK. The hard, fast rule was that if you made any mistake for the first time the entire team would have your back in fixing that mistake if anything went wrong. However, if you ever repeated the mistake a second time, then you were 100 percent on your own to face the consequences.  This rule applied for every first-time occurrence of each new mistake you made.

We all make mistakes. Every one of us. If we aren’t making mistakes, then we likely aren’t trying enough new things outside our comfort zone, and that itself is a mistake. That process is the best way to learn and grow as a person.  As John Wooden once said, “If you’re not making mistakes, then you’re not doing anything.” Mistakes are the pathway to great ideas and innovation. Mistakes are the stepping stones to moving outside the comfort zone to the growing zone where new discoveries are made and great lessons are learned. Mistakes are not failures, they are simply the process of eliminating ways that won’t work in order to come closer to the ways that will.
Great leaders allow their people the freedom to make mistakes. But good employees are those who when mistakes are made 1. Learn from them, 2. Own them, 3. Fix them, and 4. Put safeguards in place to ensure the same mistake will never be repeated again.
1.       Learn from them:  Good employees recognize that they have, in fact, made an honest mistake.  They do not get defensive about it, rather they are willing to look objectively at their mistake, recognize what they did wrong, and understand why their choice or actions were the wrong thing to do.
2.       Own them:  Good employees take accountability for their mistakes. They admit them readily.  They don’t make excuses for their mistake, rather they acknowledge that yes, they made a mistake and they express openly what lesson they have learned from that mistake. They go on to express steps 3 and 4 below.
3.       Fix them: Good employees do what it takes to rectify their wrongs. They are willing to do whatever they can to fix the problem and make it right. Certainly there are times when the damage is done and recompense cannot be made, but good employees do their very best to repair whatever damage has been done to the best of their ability. They always establish a timeline with follow up for when the problem will be fixed and make sure that progress is communicated throughout the process so everyone feels the urgency and care with which they are correcting the problem.
4.       Put safeguards in place to ensure the same mistake will never be repeated again: This is the most critical step in the learning process. When a mistake has clearly been made, the most important thing anyone can do is figure out what safety nets and roadblocks can be carefully established to ensure that this same mistake will never take place again. Document this step so the lessons learned and the safeguards setup can always go beyond you. Do everything in your power to help others learn from your mistake so they don’t have to experience them on their own to gain the lesson you’ve learned.
The steps to correcting mistakes apply to any area of life. Whether it’s business life or home life or personal life, the principles of apologizing remain the same. Good employees make a lot of mistakes, and truly great employees are those have mastered the art of apologizing for those mistakes:
Great People Practice The Six A’s of a Proper Apology:
  • Admit - I made a mistake.
  • Apologize - I am sorry for making the mistake.
  • Acknowledge - I recognize where I went wrong that caused my mistake to occur.
  • Attest - I plan to do the following to fix the mistake on this specific timeline.
  • Assure - I will put the following protections in place to ensure that I do not make the same mistake again.
  • Abstain – Never repeat that same mistake twice.
People who implement the Six A’s will find that the level of trust and respect others have for them will grow tenfold. People who implement the Six A’s will find that others will be quicker to forgive them and more likely to extend a second chance. It’s not the making of a mistake that is generally the problem; it’s what you do with it afterward that really counts.

Important Interview questions on ASP.NET

  1. Whats an assembly? Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.
  2. Describe the difference between inline and code behind – which is best in a loosely coupled solution? ASP.NET supports two modes of page development: Page logic code that is written inside <script runat=server> blocks within an .aspx file and dynamically compiled the first time the page is requested on the server. Page logic code that is written within an external class that is compiled prior to deployment on a server and linked “behind” the .aspx file at run time.
  3. Explain what a diffgram is, and a good use for one? A DiffGram is an XML format that is used to identify current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection. When a DataSet is written as a DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the contents, though not the schema, of the DataSet, including column values from both the Original and Current row versions, row error information, and row order.
  4. Where would you use an iHTTPModule, and what are the limitations of anyapproach you might take in implementing one? One of ASP.NET’s most useful features is the extensibility of the HTTP pipeline, the path that data takes between client and server. You can use them to extend your ASP.NET applications by adding pre- and post-processing to each HTTP request coming into your application. For example, if you wanted custom authentication facilities for your application, the best technique would be to intercept the request when it comes in and process the request in a custom HTTP module.
  5. In what order do the events of an ASPX page execute. As a developer is it important to undertsand these events? Every Page object (which your .aspx page is) has nine events, most of which you will not have to worry about in your day to day dealings with ASP.NET. The three that you will deal with the most are: Page_Init, Page_Load, Page_PreRender.
  6. Which method do you invoke on the DataAdapter control to load your generated dataset with data?
If my DataAdapter is sqlDataAdapter and my DataSet is dsUsers then it is called this way:
  1. Which template must you provide, in order to display data in a Repeater control? ItemTemplate
  2. How can you provide an alternating color scheme in a Repeater control?
AlternatingItemTemplate Like the ItemTemplate element, but rendered for every other
row (alternating items) in the Repeater control. You can specify a different appearance
for the AlternatingItemTemplate element by setting its style properties.
  1. What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?
You must set the DataMember property which Gets or sets the specific table in the DataSource to bind to the control and the DataBind method to bind data from a source to a server control. This method is commonly used after retrieving a data set through a database query.
  1. What base class do all Web Forms inherit from?
  2. What method do you use to explicitly kill a user’s session?
The Abandon method destroys all the objects stored in a Session object and releases their resources.
If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.
Syntax: Session.Abandon
  1. How do you turn off cookies for one page in your site?
    Use the Cookie.Discard Property which Gets or sets the discard flag set by the server. When true, this
    property instructs the client application not to save the Cookie on the user’s hard disk when a session ends.
  2. Which two properties are on every validation control? ControlToValidate & ErrorMessage properties
  3. How do you create a permanent cookie? Setting the Expires property to MinValue means that the Cookie never expires.
  4. Which method do you use to redirect the user to another page without performing a round trip to the client? Server.transfer()
  5. What is the transport protocol you use to call a Web service? SOAP. Transport Protocols: It is essential for the acceptance of Web Services that they are based on established Internet infrastructure. This in fact imposes the usage of of the HTTP, SMTP and FTP protocols based on the TCP/IP family of transports. Messaging Protocol: The format of messages exchanged between Web Services clients and Web Services should be vendor neutral and should not carry details about the technology used to implement the service. Also, the message format should allow for extensions and different bindings to specific transport protocols. SOAP and ebXML Transport are specifications which fulfill these requirements. We expect that the W3C XML Protocol Working Group defines a successor standard.
  6. True or False: A Web service can only be written in .NET. False.
  7. What does WSDL stand for? Web Services Description Language
  8. What property do you have to set to tell the grid which page to go to when using the Pager object?
  9. Where on the Internet would you look for Web services? UDDI repositaries like uddi.microsoft.com, IBM UDDI node, UDDI Registries in Google Directory, enthusiast sites like XMethods.net.
  10. What tags do you need to add within the asp:datagrid tags to bind columns manually? Column tag and an ASP:databound tag.
  11. How is a property designated as read-only? In VB.NET:
Public ReadOnly Property PropertyName As ReturnType
  Get             ‘Your Property Implementation goes in here
  End Get
End Property
in C#
public returntype PropertyName
           //property implementation goes here
   // Do not write the set implementation
  1. Which control would you use if you needed to make sure the values in two different controls matched? Use the CompareValidator control to compare the values
    of 2 different controls.
  2. True or False: To test a Web service you must create a windows application or Web application to consume this service? False.
How many classes can a single .NET DLL contain? Unlimited