Tuesday, November 29, 2011

ADO.NET interview questions: - Elaborate different implementing ways of optimistic locking in ADO.NET.

This is one of the ADO.NET interview questions asked in the interview. Answer this question with the simple steps as follows.

Ways to implement optimistic locking using ADO.NET: -
  • When we call “Update” method of Data Adapter it handles locking internally. If the Dataset values are not matching with current data in Database, it raises concurrency exception error. We can easily trap this error using Try. Catch block and raise appropriate error message to the user.
  • Define a Date time stamp field in the table. When actually you are firing the UPDATE SQL statements, compare the current timestamp with one existing in the database. Below is a sample SQL which checks for timestamp before updating and any mismatch in timestamp it will not update the records. This I the best practice used by industries for locking.
Update table1 set field1=@test where Last Timestamp=@Current Timestamp
  • Check for original values stored in SQL SERVER and actual changed values. In stored procedure check before updating that the old data is same as the current Example in the below shown SQL before updating field1 we check that is the old field1 value same. If not then some one else has updated and necessary action has to be taken.
Update table1 set field1=@test where field1 = @oldfield1value

Locking can be handled at ADO.NET side or at SQL SERVER side i.e. in stored procedures: -

Also see the following video on Table Scan And Unique key in SQL Server: -



Please click here to see more ADO.NET interview questions

Regards,

Visit Authors blog for more ADO.NET interview questions

Friday, November 25, 2011

.NET interview questions: - Similarities and Differences between Classes and structures.

One of the most likely .NET interview questions asked in the interview, so you should include the following points in your answers.
Similarities between classes and structures: -
  • Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
  • Structures and classes can implement interface.
  • Both of them can have constructors with and without parameter.
Both can have delegates and events.

Key differences are: -
  • Structures are value types and classes are reference types. So structures use stack and classes use heap.
  • Structures members cannot be declared as protected, but class members can be. You cannot do inheritance in structures.
  • Structures do not require constructors while classes require.
  • Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.
Following you can see video on regular expressions with some practical demonstrations: -


Please click here to see more Dotnet interview questions and answers

Regards,

Visit Authors blog for more Most asked .NET interview questions

Saturday, November 19, 2011

.Net Interview questions: - What is GAC, add/remove an assembly from GAC and how do we make choices between 2 versions of the same assembly?

This .NET interview questions will make you remember the basics of .NET if you are senior person in the .NET industry. For the fresher it is still a hiccup so one can start answering the same as follows: -

About GAC: -

GAC (Global Assembly Cache) is where all shared .NET assembly resides. GAC is used in the following situations: -
  • If the application has to be shared among several application which is in the same computer.
  • If the assembly has some special security, requirements like only administrators can remove the assembly. If the assembly is private then a simple delete of assembly the assembly file will remove the assembly.
Add/remove an assembly from GAC: -

You can use the ‘GACUTIL’ tool which comes with visual studio. So to register an assembly in to GAC go to “Visual Studio Command Prompt” and type “gacutil –i (assembly name)”, where (assembly name) is the DLL name of the project.

One you have installed the assembly the DLL can be seen in ‘c:\windows\assembly\’ folder.

When we have many DLL’s to be deployed we need to create setup and deployment package using windows installer. So the common way of deploying GAC DLL in production is by using windows installer.

Making choice between two versions of the same assembly in GAC: -

When we have two version of the same assembly in GAC we need to use binding redirect tag and specify the version we want to use in the new version property as shown in the below “app.config” file.




Get ready to see more basics videos of .NET interview questions on Garbage Collector, Gen 0, 1 & 2 as follows: -



Get more fundamentals stuffs on interview questions and answers for .NET
Regards,

More from author’s blogs on Most asked Dotnet interview question for interview references.

Wednesday, November 16, 2011

WCF interview questions: - Using which binding we can build WCF REST?

This is one of the asked WCF interview questions during the interview. So one proceed answer as the following: -

For WCF REST we need to use WebHttpBinding. WebhttpBinding is enabled by as shown in the below code snippet.




Also see our following video on explanation of REST: -


Click and get to see more on WCF Interview questions series.

Regards,

Also visit author’s blog for more WCF interview questions

Saturday, November 12, 2011

SQL Server Interview Question - How do we connect to SQL SERVER, which namespace do we use?

This SQL Server interview questions is more of practical oriented. Below is the code to connect SQL Server, then we will try to understand the same in a more detailed manner.

Private Sub LoadData()
‘ note :- with and end with makes your code more readable
Dim strConnectionString As String
Dim objConnection As New SqlConnection
Dim objCommand As New SqlCommand
Dim objReader As SqlDataReader
Try
‘ this gets the connectionstring from the app.config file.
‘ note if this gives error see where the MDB file is stored 
  in your pc and point to thastrConnectionString = AppSettings.Item
(“ConnectionString”)
‘ take the connectiostring and initialize the connection object
With objConnection
.ConnectionString = strConnectionString
.Open()
End With
objCommand = New SqlCommand(“Select FirstName from Employees”)
With objCommand
.Connection = objConnection
objReader = .ExecuteReader()
End With
‘ looping through the reader to fill the list box
Do While objReader.Read()
lstData.Items.Add(objReader.Item(“FirstName”))
Loop
Catch ex As Exception
Throw ex
Finally
objConnection.Close()
End Try
<appSettings>
<add key=”Connectionstring” value=”Server=ERMBOM1-IT2;User ID=sa;Database=Employees”/>
</appSettings>
 
Note:- Comments in the code do explain a lot but we will again iterate through the 
whole code later. “LoadData” is the main method which loads the data from SQL SERVER. 
Before running this code you have to install SQL SERVER in your machine. As we are dealing 
with SQLCLIENT we need to setup database in SQL SERVER. Depending on computer you will 
also have to change the connectionstring in Web.config file.
 
For setting up the sample SQL table, we can use the DTS import wizard to import the table. See the below figure which is using data source as Microsoft Access. While importing the database author had, give the database name as “Employees”.

Figure: - Loading “Nwind.mdb” in SQL SERVER
 



Figure: - Load only the Employee table.

To make it simple we will only import the employee table as that is the only thing needed in our sample code.

 












Figure: - View of loaded Employee table

Now from interview point of view definitely you are not going to say the whole source code, which is given in the book. Interviewer expects only the broader answer of what are the steps needed to connect to SQL SERVER. For fundamental sake author has explained the whole source code. In short, you have to explain the “Load Data” method in broader way. Following are the steps to connect to SQL SERVER:-

• First imports the namespace “System.Data.SqlClient”.
• Create a connection object as shown in “Load Data” method.

With objConnection
.Connection String = strConnectionString
.Open ()
End With
• Create the command object with the SQL. Also, assign the created connection object to command object and execute the reader.

ObjCommand = New SqlCommand (“Select First Name from Employees”)
With objCommand
.Connection = objConnection
Breeder = .Execute Reader ()
End With
• Finally loop through the reader and fill the list box. If old VB programmers are expecting the move next command it is replaced by Read () which returns true if there is any data to be read. If the .Read () return is false that means that it’s end of data reader and there is no more data to be read.

Do while objReader.Read ()
lstData.Items.Add (objReader.Item (“First Name”))
Loop
• Do not forget to close the connection object.

See the following video on use of SQL Server in SharePoint and use of virtual path provider














More stuffs on SQL Server interview questions for interview preparation.

Regards,

Go to author’s blog for typical other  SQL Server interview questions

Thursday, November 10, 2011

ADO.NET interview questions: - What are the namespaces provided by .NET for data management?


Following are the namespaces provided by .NET for data management:-
System.Data

This namespace has the dataset object which helps us to access data in a data source independent manner.
System.Data.SqlClient:

This namespace has objects which helps us to connect to SQL Server database.
System.Data.OleDB

This namespace has objects which helps us to connect to other databases like Oracle, Access and also SQL Server database.
System.XML

This Contains the basic objects required to create, read, store, write, and manipulate XML documents.














ADO.NET namespaces

See the following video on calling a stored procedure using LINQ: -













Avail from the link more ADO.NET interview questions for preparation.

Regards,

Refer author’s other blog for complete ADO.NET interview questions

Tuesday, November 8, 2011

ADO.NET interview questions: - Different components in ADO.NET.

There are 6 important components in ADO.NET:-
  • Connection: -This object creates a connection to the database. If you want to do any operation on the database you have to first create a connection object.
  • Command: -This object helps us to execute SQL queries against database. Using command object we can execute select, insert, update and delete SQL command.
  • Data reader: - This provides a recordset which can be browsed only in forward direction. It can only be read but not updated. Data reader is good for large number of records where you want to just browse quickly and display it.
  • Dataset object: -This provides a recordset which can be read back and in forward direction. The recordset can also be updated. Dataset is like a in memory database with tables, rows and fields.
  • Data Adapter: -This object acts as a bridge between database and dataset; it helps to load the dataset object.
  • Data View: - This object is used to sort and filter data in Data table of dataset.


                                                     Figure: - ADO.NET architecture

See the following video on Table Scan and Unique key in SQL Server: -



Get more on ADO.NET interview questions

Regards,

For more on ADO.NET interview questions from author’s blog.

Sunday, November 6, 2011

SQL Server interview questions - What is meant by Referential Integrity in SQL Server?


This is one the typical SQL interview questions and also the favorable question of the interviewers, which has been asked in most of the .NET interviews.

Referential Integrity: - Referential Integrity is a DataBase concept that ensures the relationship between tables remains consistent, where one table has a foreign key reference to the other table which is declared as primary key.

In simply words when a relation is maintained between two table’s using primary key and foreign key reference is called as Referential Integrity.

Let’s see a simple demonstration to understand the concept of Referential Integrity.

In order see it practically you just need to follow the following steps.

Step1: - Let’s first create Two Tables like below diagram with respective relationship.
1. Creating a Customer Table.
Query: -
create table Customer
(
CustID int primary key,
CustomerName varchar(50)
);
 
 









In the above table of customer you can see that I have created two columns with one as primary key.
2. Similarly, let’s create second table name as CustomerDetails.

Query: -
create table CustomerDetails 
(CustID int Foreign key references Customer(CustID),
CustDetailsID int primary key,
CustOrders varchar(50)
);
 
 















In the above table of CustomerDetails you can see that I have declared CustID as foreign key references to the Customer (CustId) table.

Step2: - Now, let’s Insert some data to both the table’s.

Query: - Inserting into Customer Table.

insert into dbo.Customer(CustID,CustomerName)values(1,'Kalim')
insert into dbo.Customer(CustID,CustomerName)values(2,'Wasim')
insert into dbo.Customer(CustID,CustomerName)values(3,'Salim')
insert into dbo.Customer(CustID,CustomerName)values(4,'Nadeem')
 













Query: - Inerting into CustomerDetails Table.

insert into dbo.CustomerDetails(CustID ,CustDetailsID ,CustOrders ) 
values(1,1,'Pizza')
insert into dbo.CustomerDetails(CustID ,CustDetailsID ,CustOrders ) 
values(1,2,'Pepsi')
insert into dbo.CustomerDetails(CustID ,CustDetailsID ,CustOrders ) 
values(3,3,'Veg-Roll')
insert into dbo.CustomerDetails(CustID ,CustDetailsID ,CustOrders ) 
values(2,4,'Chicken-Pizza')
 












Note: - When there is Referential Integrity between two table’s then you cannot delete record from the respective table.

Step3: - Let’s see a example to prove the above mentioned note.

So, let’s try to delete record from the Customer table and see what is the output.

Query: -
delete from Customer where CustID = 1
As soon as you click on execute you will output result like below diagram.

 






In the above output result diagram you can clearly see that the compiler does not allow deleting record from the table. Which means that, when there is relation maintains between two table’s using Referential Integrity you cannot delete records from the respective tables.

See the following video on the differences between unique key and primary key as follows: -






Get more on SQL Server interview questions

Regards,

See for author’s other blog on SQL Server interview questions

Friday, November 4, 2011

.NET interview questions: – CAS model under .NET 4.0

Under .NET 4.0 for CAS there are two major changes are brought in: -  •

Permission granting is no more the work of CAS; it’s now the work of the hosting model. In other words CAS is disabled in .NET 4.0 by default. The host will decide what rights to be given to the .NET assembly.

A new security model i.e. Security transparent model is introduced. The security transparent model puts code in to separate compartments/ boxes as per the risk associated. If you know a code can do something wrong you can compartmentalizethe code as ‘Security transparent’ and if you have a code which you trust you can box them in to ‘Security critical’.

CAS Model: -

Security transparent code is the code which you feel is unsafe and security safe critical code is the code which you feel is safe and has full access to the system. Security transparent code cannot call critical code directly, if they have to then they need to go through security safe critical code.

Figure: - .NET 4.0 CAS model 

Also see as detailed video on CAS which explains evidence, permission set & code groups as follows:

 

Get more for  for interview questions and answers for Dotnet complete preparation.

Regards,

Refer author’s other blog for complete Most asked Dotnet interview question