Friday, November 14, 2014

Debugging production issues

Some times we get weird issues in production and some of they are not consistent and canot be reproduced in development environment.To deal with such issues I am giving some tips based on my experience.

1)Fist thing we need to do is to check the application log files and database log tables and see if the information logged will help us in anyway to understand the root cause.If the information is not sufficient we can add extra logging and deploy the latest code to capture more information.

In below method we are capturing empId for additional information regarding the exceptional scenario.There are cases issues can be occurred for only particular employee so empId will help us in understanding the all employee information.

public List<Employee> GetEmployee(string empId)
{
............
}
catch (Exception exception)
{
var exMessage = exception.Message + Environment.NewLine +
exception.StackTrace + Environment.NewLine + "EmplId:" + empId;

Logger.Write(ErrorLogTittle, exMessage);
}

In GetEmployee method if there is any exception occurred it will log exception message,StackTrace and also empId.
StackTrace will help us in identifying the code file and line no apart from exception details.
Logging transaction details like empId is very important to find the root cause in some weird cases.
Catching the exceptions and logging the details in database table and also a text file before displaying the error to user should be compulsory.

In some scenarios,we might need to add additional logs to track the work flow.
a)Record processing started
b)Reading employee details
C).....
d)End
This way we can easily identify after which step the exception occurred.

2)In some scenarios like below
a)If our application is trying to access remote machines/Network resources.
b)Need some dll's for application functioning but unable to load.

We can get helpful information to identify the root cause from Windows event logs.

To check event logs,Open Run dialog box type and type eventvwr. Expand Windows Logs and click on Application. It will display the list of all application events.It will display 3 types of information.They are Information,Warning and Error.We know where to check right?


I will try to add more tips later.. :-)

Tuesday, October 28, 2014

Connection Pooling in ADO.NET

Connecting to any database from code is a time consuming process. Of course,may not be more than few milliseconds but when thousands of users are accessing your website it will affect the performance of the application.Similar database connections will be opened and closed to perform the client requests.

To optimize the creation and utilization of data base connections ADO.NET provided a concept called connection pooling.If connection polling is enabled and user calls connection Open, instead of directly creating the connection, the ADO.NET will first check if there are any active connections in the pool,If any active connections are available it will return the connection from the pool otherwise a new connection will be created.When the application Close the connection it will be returned to the pool.

Connection pools are created based on Connection strings.Two connection pools will be created if two connection strings differed even in the order of connection properties though their values are same.

By Default connection Pooling is Enabled in ADO.NET

Below are the important Connection Pooling attributes or properties.

Pooling:When its true,A connection will be created in the first request and will be returned to the pool after its usage.

Connection Lifetime (or Load Balance Timeout): Life time of the active connections in the pool.If a connection exceeds this value then connection will be destroyed. This time out is useful in load balance scenarios.

Default value is 0 seconds. Value 0 causes the maximum time out for connections.

Connection Timeout: Maximum time the connection waits for response to be returned by the server. Default value is 15 seconds.

Enlist: When Enlist is true, pooler enlists the connection in creation threads current transaction context.

Max Pool Size: Indicates the maximum number of connections allowed inside the connection pool. Default value is 100. Max Pool Size should always be greater than or equal to Min Pool Size.

Min Pool Size:Indicates the minimum number of connections allowed inside the pool.Default value is 0. Min Pool Size should always be less than or equal to Max Pool Size.

Sample connection string with connection pooling:

<add name="SampleConnectionString" connectionString="Data Source=localhost;Initial Catalog=SampleDataBase;Persist Security Info=True;User ID=sa;Password=Sky#1;Connection Timeout=30;Min Pool Size=5;Max Pool Size=20;Pooling=True;Connection Lifetime=0;Enlist=True;" providerName="System.Data.SqlClient" />

Friday, October 10, 2014

What is .NET?

1)Microsoft .Net is a technology platform developed by Microsoft corporation and it helps in platform neutral and language independent application development.

2)Microsoft .NET is a frame work which supports development of different applications like Windows applications,Web applications,Mobile applications and Web services etc.,

3)It provides a consistent object oriented programming environment.

4).NET framework has two main components.They are
 a)CLR(Common language runtime) and b)Framework class library.

CLR is the main component responsible for running the .NET code on operating systems and it also provides different services like memory management,exception handling,threading etc.

Framework class library basically provides the support for development of different applications.It supports different code libraries which developers can use to develop their applications.

5)Microsoft .Net uses Common type system for language interoperability.

CTS has some set of standards to which all the .Net compilers must follow to have the code written in one language to be understood by other languages.