Hi..All..I want to design a n tire architecture in my application.I've gone through many sites and have understood the concept but I don't how to start it.
I've very basic questions like..how do I create the layer and How do I connect between the layers..
Would you please help and if you have any sample coding(VB.NET) pls send it to me..
Thanxs
Tany

Dani AI

Generated

@n-tier is a design approach, not a single library or file dump — was right about that. Treat it as clear responsibility boundaries: presentation (ASP.NET pages), business rules, data access, and simple DTO/entities. ’s suggestion to sketch layers first is sensible — list the screens, the data each needs, and the business rules that sit between them.

A practical start: create one Visual Studio solution with small class-library projects for Entities, DataAccess, and Business, plus the Web project. Keep references one-way (Web -> Business -> Data -> Entities). Put the connection string in web.config and pass it into the DAL (or register a factory) so the DAL isn’t tightly coupled to config. Use interfaces for repositories so the Business layer can be unit-tested or mocked. Avoid returning open DataReaders from the DAL — always materialize entities inside the DAL and close connections there.

Example (very small) showing an entity and a safe DAL method in VB.NET:

' MyApp.Entities
Public Class Customer
    Private _id As Integer
    Private _name As String

    Public Property CustomerID() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
End Class

' MyApp.Data (simplified)
Imports System.Data.SqlClient

Public Class CustomerRepository
    Private ReadOnly _conn As String

    Public Sub New(ByVal connectionString As String)
        _conn = connectionString
    End Sub

    Public Function GetById(ByVal id As Integer) As Customer
        Using cn As New SqlConnection(_conn)
            Using cmd As New SqlCommand("SELECT CustomerID, Name FROM Customers WHERE CustomerID = @id", cn)
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = id
                cn.Open()
                Using rdr = cmd.ExecuteReader()
                    If rdr.Read() Then
                        Dim c As New Customer()
                        c.CustomerID = Convert.ToInt32(rdr("CustomerID"))
                        c.Name = Convert.ToString(rdr("Name"))
                        Return c
                    End If
                End Using
            End Using
        End Using
        Return Nothing
    End Function
End Class

Common pitfalls to avoid: circular project references, putting business rules in code-behind, leaking connections/readers, and static singletons that hard-code config. ’s pointer to examples can help once the structure is understood, but the immediate value comes from separating concerns, wiring simple interfaces, and iterating with tiny working pieces.

Recommended Answers

All 3 Replies

No one is going to send you any code, as that totally defeats the spirit of a forum.

"n-tier architecture", with various "layers", is a philosophical thing. In terms of actual coding, all it really means is that you organize things in a logical manner.

For example, all the code to interact with your database, should be in its own class. To write something to a database, your application would use the members of your "db" class.

to make an application as n tier, first you need to design all layers its just paper work, what database or how many tables require then create your database, once you create all tables or you database now you have to create front end of your apllication so create view of you application whatever your application reqiurements then now make controls which are used in the application.


actually n tier architecture is talk about the separete layers, like you need to create data components seperate from your code behind logic, and your front end page, you just need to connect or use all components where ever need it in code part.

Click the below link for N tier Architecture :

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.