Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello Code Project,

Recently, I checked the N-Tier Architecture in C#.Net. I would like to ask (newbie question) if what architecture used is when I put dbLayer class in my application/web?

Example code in dbLayer.cs

C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
 
/// <summary>
/// Summary description for dbLayer
/// </summary>
public class dbLayer
{
    private string gConnString;
    public dbLayer(string strConnn)
    {
        gConnString = strConnn;
    }
 
    public void WebConfig_ActivityLog(string username, string activity)
    {
        SqlConnection sqlConn = new SqlConnection();
        SqlCommand sqlCmd = new SqlCommand();
 
        sqlConn.ConnectionString = gConnString;
 
        sqlCmd.CommandText = "dbo.[sp_Activity_Trail]";
        sqlCmd.CommandType = CommandType.StoredProcedure;
        sqlCmd.Connection = sqlConn;
 
        sqlCmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@username", SqlDbType.VarChar, 255));
        sqlCmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@activity", SqlDbType.VarChar, 4000));
 
        sqlCmd.Parameters["@username"].Value = username;
        sqlCmd.Parameters["@activity"].Value = activity;
 
        try
        {
            sqlConn.Open();
            sqlCmd.ExecuteNonQuery();
        }
        catch (Exception objExp)
        {
            throw objExp;
        }
        finally
        {
            if (sqlConn != null && sqlConn.State != System.Data.ConnectionState.Closed)
            {
                sqlConn.Close();
            }
        }
    }
}


Thank you!

What I have tried:

Confirmation and checking google from different architecture.
Posted
Updated 9-May-16 23:44pm

1 solution

Depends on where you put this class. And what it does. It is not DAL just because it is called dbLayer (MS recommends having PascalCase class names, so DBLayer or DbLayer instead of dbLayer)

You should have project layout something like this (each of these is separate project, dll) except for UI which is part of the initial project/solution for deployment:
UI (HTML Pages and their code behind)
BusinessLogic (domain objects and controllers)
Data Access Layer (called from BL for data access)
Common (things shared across the projects, various extensions, enums, constants, interfaces etc.)
 
Share this answer
 
v2
Comments
rockitech 10-May-16 4:58am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900