Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service I am wondering for classes such as SqlConnection or one of the several classes
Generally we are facing issue in Close(), Abort() and Dispose() but let me tell you difference among them.
1) ABORT:- I won't suggest to use this because when abort is called the client will delete the connection without telling the server so server will wait for some amount of time (approximately 1 min). If you having bulk request then you can't use abort() because it may caused time out for your limited connection pool.
2) Close:- Close is very good way to closing the connection because when closing the connection it will call server and acknowledge the server to close by that side too.
Here, one more thing to look. In some cases, if error generates then it is not a good way to write code in finally that connection.close() because at that time Communication State will be faulted.
3) Dispose :- It is one type of close but after closing the connection you can not open it again.
So try this way ,
private void CloseConnection(Client client)
{
if (client != null && client.State == CommunicationState.Opened)
{
client.Close();
}
else
{
client.Abort();
}
}