Click here to Skip to main content
15,881,812 members
Articles / Web Development / ASP.NET

Designing and implementing a versatile data access tier for an ASP.NET application

Rate me:
Please Sign up or sign in to vote.
4.63/5 (45 votes)
3 Feb 200328 min read 384.4K   3.8K   242  
In this article, we will drill down deeper in to the design of a n-tier architecture and our focus will be on the data access tier (DAT)
using System;
using System.Diagnostics;
using System.Configuration;

namespace BLT
{
	/// <summary>
	/// Summary description for BLBasis.
	/// </summary>
	public class BLBasis
	{

		// EventLog for Buisness Logic Tier
		protected static EventLog daEventLog;
		// strings to connect EventLog
		protected static string strLog;
		protected static string strSource;
		protected static string strMachine;

		protected static decimal dConsumeTaxRate;
		public BLBasis()
		{
			
		}

		static BLBasis()
		{
			// strings to connect the EventLog
			strLog = ConfigurationSettings.AppSettings["blLog"];
			strSource = ConfigurationSettings.AppSettings["blSource"];
			strMachine = ConfigurationSettings.AppSettings["blMachine"];
			dConsumeTaxRate = Convert.ToDecimal(ConfigurationSettings.AppSettings["consumeTaxRate"]);
			// Create an instance from EventLog
			if(EventLog.SourceExists(strLog,strMachine))
			{
				daEventLog = new EventLog(strLog,strMachine,strSource);
			}
		}

		/// <summary>
		/// Writes error messages in to the EventLog
		/// </summary>
		/// <param name="strMessage"></param>
	    protected virtual void ErrorLog(string strMessage)
		{
			// write in Windows EventLog
			if(daEventLog!=null)
			{
				daEventLog.WriteEntry(strMessage,EventLogEntryType.Error);
			}
			// throw an error to the buisness access tier
			Exception oException= new Exception("An error occured in  BLTier ");
			throw oException;
		}

		/// <summary>
		///  Writes error messages in to the EventLog
		/// </summary>
		/// <param name="strMessage"></param>
		/// <param name="oException"></param>
		protected virtual void ErrorLog(string strMessage,Exception oException)
		{
			// write in Windows EventLog
			if(daEventLog!=null)
			{
				string oMessage = oException.Message + " " + strMessage;
				daEventLog.WriteEntry(oMessage,EventLogEntryType.Error);
			}
			// throw an error to the 
			Exception oExcept= new Exception("An error occured in  BLTier");
			throw oExcept;
		}
       

		/// <summary>
		/// Writes warning messages on the EventLog
		/// </summary>
		/// <param name="strMessage"></param>
		protected void WarningLog(string strMessage)
		{
			// write in Windows EventLog
			if(daEventLog!=null)
			{
				daEventLog.WriteEntry(strMessage,EventLogEntryType.Warning);
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Switzerland Switzerland
Paul Abraham is a software developer who designs and develops multi-shop systems.

He has received his M.Sc in Mathematics and Computer Science from the FernUniversität Hagen(http://www.fernuni-hagen.de Germany) and his main interests are neural networks and bayesian statistics He lives in Rosenheim (South Germany http://www.rosenheim.de). You can reach him at admin@paul-abraham.com.

Comments and Discussions