public class DbServices
{
#region Methods
/// <summary>
/// Fo Handle Db Services
/// </summary>
/// <CreatedBy>Sumesh.N</CreatedBy>
/// <CreatedOn>19-Jan-2012 03:00 PM</CreatedOn>
SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings[DbServiceConst.DB_Connection].ConnectionString);//+ EncryptionDecryption.DecryptString( ConfigurationManager.ConnectionStrings[DbServiceConst.DB_ConnectionPwd].ConnectionString,true));
/// <summary>
/// Method to create Connection
/// </summary>
/// <returns></returns>
/// <remarks></remarks>
private SqlConnection GetConnection()
{
if (objConn.State == ConnectionState.Closed)
{
objConn.Open();
}
return objConn;
}
/// <summary>
/// Mehtod to Close sql connection
/// </summary>
/// <returns></returns>
/// <remarks></remarks>
public bool CloseConnection()
{
if (objConn.State != ConnectionState.Closed)
{
objConn.Close();
return true;
}
else
{
return false;
}
}
/// <summary>
/// Method to Execute procedure
/// </summary>
/// <param name="objCmd"></param>
/// <returns></returns>
/// <remarks></remarks>
public int ExecuteProcedure(SqlCommand objCmd)
{
objCmd.Connection = GetConnection();
int i = objCmd.ExecuteNonQuery();
CloseConnection();
return i;
}
/// <summary>
/// Method to Execute Scalar
/// </summary>
/// <param name="objCmd"></param>
/// <returns></returns>
public object ExecuteScalar(SqlCommand objCmd)
{
objCmd.Connection = GetConnection();
object value = objCmd.ExecuteScalar();
CloseConnection();
return value;
}
/// <summary>
/// Method to Execute Reader
/// </summary>
/// <param name="objCmd"></param>
/// <returns></returns>
public SqlDataReader ExecuteReader(SqlCommand objCmd)
{
objCmd.Connection = GetConnection();
SqlDataReader rdr = null;
rdr = objCmd.ExecuteReader();
return rdr;
}
#endregion
}
{
#region Methods
/// <summary>
/// Fo Handle Db Services
/// </summary>
/// <CreatedBy>Sumesh.N</CreatedBy>
/// <CreatedOn>19-Jan-2012 03:00 PM</CreatedOn>
SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings[DbServiceConst.DB_Connection].ConnectionString);//+ EncryptionDecryption.DecryptString( ConfigurationManager.ConnectionStrings[DbServiceConst.DB_ConnectionPwd].ConnectionString,true));
/// <summary>
/// Method to create Connection
/// </summary>
/// <returns></returns>
/// <remarks></remarks>
private SqlConnection GetConnection()
{
if (objConn.State == ConnectionState.Closed)
{
objConn.Open();
}
return objConn;
}
/// <summary>
/// Mehtod to Close sql connection
/// </summary>
/// <returns></returns>
/// <remarks></remarks>
public bool CloseConnection()
{
if (objConn.State != ConnectionState.Closed)
{
objConn.Close();
return true;
}
else
{
return false;
}
}
/// <summary>
/// Method to Execute procedure
/// </summary>
/// <param name="objCmd"></param>
/// <returns></returns>
/// <remarks></remarks>
public int ExecuteProcedure(SqlCommand objCmd)
{
objCmd.Connection = GetConnection();
int i = objCmd.ExecuteNonQuery();
CloseConnection();
return i;
}
/// <summary>
/// Method to Execute Scalar
/// </summary>
/// <param name="objCmd"></param>
/// <returns></returns>
public object ExecuteScalar(SqlCommand objCmd)
{
objCmd.Connection = GetConnection();
object value = objCmd.ExecuteScalar();
CloseConnection();
return value;
}
/// <summary>
/// Method to Execute Reader
/// </summary>
/// <param name="objCmd"></param>
/// <returns></returns>
public SqlDataReader ExecuteReader(SqlCommand objCmd)
{
objCmd.Connection = GetConnection();
SqlDataReader rdr = null;
rdr = objCmd.ExecuteReader();
return rdr;
}
#endregion
}
No comments:
Post a Comment