Wednesday, February 27, 2013

Difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio

This blog will explain the difference between Build, Rebuild and Clean solution in visual studio:


difference between Build, Rebuild and Clean solution
Build vs Rebuild

Build: it complies and links only those source code files DLL /EXE that have changed since the last build. So normally build is faster than Rebuild and it build only those project, which have changed source code.

Rebuild : it clean all project artifices (clean bin folder)  and compile and link all source code files from scratch regardless of whether they changed or not.

Clean: it deletes all compiled files (DLL and EXE files)


Thanks for visiting!!

Friday, February 15, 2013

WCF : System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host

WCF : System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
Exception:  'System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host'



I  recently encountered WCF socketException and found that there could be majorly two reasons for this issue
  • Service Proxy was ideal for almost 10 minutes and after we can try to use the same service proxy.
  • Service is slowness, in this case, Service response time is crossed the default value of receiving timeout 
Considering the above two points, I made following changes in service config file, after that refreshed the client proxy with latest settings


1.       Increased the ReceivingTimeout   value to infinity

       <binding name="netTCPBinding"   receiveTimeout"infinite" >

2.       Increased the inactivityTimeout value to infinity in reliable session setting


<reliableSession inactivityTimeout="infinite" enabled="true" />

Thanks for visiting !!

Wednesday, February 13, 2013

Entity Framework : Managing Concurrency

When multiple users try to update the same record simultaneously and system is not having the concurrency control, then users can lose their recent update data, it is called the data concurrency issue and to avoid the this situation, Entity framework is already provide the Optimistic control to handle the concurrency issue.



There are basically 3 types of concurrency controls:
1.       Optimistic Concurrency : Record will be available for user only read , if it holds by some other user
2.       Pessimistic Concurrency  : Record will not be available for user only read , if it holds by some other user
3.       "Last in wins  : None Concurrency
Entity framework is already providing the Optimistic control to handle the concurrency issue and it provides two types of concurrency modes:
·    None – This is the default and means the property is not involved in any concurrency checks
·    Fixed – Which means that the original value of this property is sent as part of the WHERE clause in all updates or deletes.

Managing Concurrency Mode
Managing Concurrency Mode


Simply, we will apply the attribute ConcurrencyMode="fixed” to entity property (timestamp property would be best choice) to handle the concurrency issue .

Thanks for visiting!


Other entity framework releated links :
Entity Framework : Bulk Update

Friday, February 8, 2013

Elements of Programming Style

We can learn , how to write the good quality of code
Please visit @ http://tarunanand.typepad.com/punjabi_by_nature/2005/09/elements_of_pro.html#comments

Good quality of code is something that when you experience it once, you will never forget it.




Sunday, February 3, 2013

WCF CommunicationObjectFaultedException - The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

WCF CommunicationObjectFaultedException -  The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

Due to some unhandled exception  or some protocol exception, network issue or binding issue like timeout etc, A channel can be faulted.

If you do not close or abort the channel in your client, you wont be able to call the service operation unless your reestablished a new communication channel between your service and client.
Any subsequent call through this faulted channel will let your Service Fault or Communication Fault exception

To avoid this faulted Exception, follow the basic approach .

1. use the Abort() method to dispose the faulted service proxy instead of calling close() method.

2. Avoid to use the using pattern to create the service proxy and follow the below pattern to create and dispose the service proxy.


           CaseServiceClient proxy = ServiceProxyManager.CreateProxy();
            try
            {
                 
             }
            finally
            {
                ServiceProxyManager.DisposeProxy(proxy);
            }

Under DisposeProxy()  method, before disposing the service proxy , we check the proxy status and according to this, we use Abort() or Close() method to dispose the service proxy


public static class  ServiceProxyManager
{
        public static void DisposeProxy(T obj)
        {
            try
            {
                if (obj != null)
                {
                    Type t = obj.GetType();
                    MethodInfo closeMethod = t.GetMethod("Close");
                    MethodInfo abortMethod = t.GetMethod("Abort");
                    PropertyInfo property = t.GetProperty("State");
                    if (property.GetValue(obj, null).ToString().Equals(CommunicationState.Faulted))
                    {
                        abortMethod.Invoke(obj, null);
                    }
                    else
                    {
                        closeMethod.Invoke(obj, null);
                    }
                }
            }
            catch (Exception ex)
            {
                UIExceptionHandler.HandleException(ex);
            }
        }




Suggested best practices for WCF  in my previous blog

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...