1.Your
Intialize
method should be made
private/protected!
2.You should use
try-catch-finally
block in all your public methods ;
3.You must take care at some disposable resources, like
SqlConnection
and
SqlReader
, that must be disposed/closed in
finally
block, not only the the case of success but also in the case of exceptions. Here is an example of improvements:
public void ExcuteReader(string query, params SqlParameter[] prmArray, UseReaderDelegate UseReader)
{
SQLConnection connection = null;
SQLDataReader sqlDataReader = null;
try{
SqlCommand cmd = Intialize(query, prmArray);
connection = cmd.Connection;
sqlDataReader = cmd.ExecuteReader();
UseReader(sqlDataReader);
}
catch(SqlException)
{
}
finally
{
if(sqlDataReader != null)
sqlDataReader.Close();
if( connection != null)
connection.Close();
}
}
PS: For more details about exception management you could read my next article (even the examples are from an ASP.NET MVC4 application the rules are the same):
MVC Basic Site: Step 2 - Exceptions Management[
^]