none
3 tier architecture RRS feed

All replies

  • Hello badri2020,

    Thanks for your post.

    Check the following links about using Visual Studio .NET Wizards to Create an N-Tiered Application by David Catherman. Please let me know if they are helpful to you.

    Part 1 : http://www.15seconds.com/issue/051103.htm (VS 2003)
    Part 2 : http://www.15seconds.com/issue/051117.htm (VS 2005)
    Part 3 : http://www.15seconds.com/issue/051123.htm

    If you have any problems, please feel free to follow up.

    Best regards,
    Liliane
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. Thanks
    Thursday, August 26, 2010 6:21 AM
  • hi,

    i am devloping a simple login program using 3 tier in vb.net....but it gives error classname cannot be indexed because it has no default property..how to overcome such error.

    guide me fast

    regards

    badri

     

    Friday, August 27, 2010 12:49 PM
  • Hello badri2020,

    You may have failed to supply a default property for a class. To correct this error, try to specify a property as the default property by starting its declaration with the default keyword. Please let me know if it helpful.

    If you still have questions, could you please provide some code which occurs the error?

    Best regards,
    Liliane
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com

     


    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. Thanks
    Monday, August 30, 2010 2:48 AM
  • hi tenq,

    i hav tried it by declaring default property for that particular variable..but it is giving some error..plz giv me syntax about how to declare default property for a variable

    thanks in advance

    regards

    badri

    Monday, August 30, 2010 9:30 AM
  • Hi badri2020,

    Please read the following link and let me know if it is helpful.
    http://msdn.microsoft.com/en-us/library/se6z814t(VS.80).aspx
    (How to: Declare and Call a Default Property in Visual Basic)

    If you still have any problems, could you please provide detail error information?

    Best regards,
    Liliane
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. Thanks
    Monday, August 30, 2010 9:42 AM
  • hi tenq,

    the link u provided doesnot exist...unable to process request error..

    plz provide some alternative links

    Monday, August 30, 2010 9:50 AM
  • Hi badri2020,

    There is no problem on my side. Could you open this link?

    http://social.msdn.microsoft.com/Search/en-US?query=How%20to%3A%20Declare%20and%20Call%20a%20Default%20Property%20in%20Visual%20Basic&ac=8

    If so, the first result is what I want to provide you. Please have a try and let me know the result.

    Best regards,
    Liliane
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. Thanks
    Monday, August 30, 2010 9:57 AM
  • s..i hav opened the link u provided...i hav declared as default property for the variable...but the variable wat we want to declare as default is actually a function..it returns some value..so how to overcome this
    Monday, August 30, 2010 10:54 AM
  • Hi badri,

    If I understand your problem correct, here is an example, could it make you get some ideas? If this is not what you want, could you describe your problem more clearly or provide some code?

    Class Class2
        ' Define a local variable to store the property value.
        Private PropertyValues As String()
        ' Define the default property.
        Default Public Property Prop1(ByVal Index As Integer) As String
            Get
                Return PropertyValues(Index)
            End Get
            Set(ByVal Value As String)
                If PropertyValues Is Nothing Then
                    ' The array contains Nothing when first accessed.
                    ReDim PropertyValues(0)
                Else
                    ' Re-dimension the array to hold the new element.
                    ReDim Preserve PropertyValues(UBound(PropertyValues) + 1)
                End If
                PropertyValues(Index) = Value
            End Set
        End Property
    End Class

    More information, please check:

    http://msdn.microsoft.com/en-us/library/az06zx4y(VS.80).aspx

    Best regards,
    Liliane
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. Thanks
    Tuesday, August 31, 2010 3:51 AM
  • hi tenq,

    i have created a login program using 3 tier architecture. The user calls it with username and password as parameters. Here is some of my code:


    Application tier
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Security.Principal
    Imports System.Threading
    Imports System.IO
    Imports System.Text
    Imports System.Collections.Generic
    Imports bal.cbal
    Namespace app
    End Namespace
    Public Class capp
        Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
            Dim verify As New bal.cbal
            Dim dat As New bal.cbal
            Dim use As String = UsernameTextBox.Text
            Dim pas As String = PasswordTextBox.Text
            verify(use, pas)
            Me.Close()
        End Sub
        Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
            Me.Close()
        End Sub
        Private Sub capp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'LoginDataSet.details' table. You can move, or remove it, as needed.
            Me.DetailsTableAdapter.Fill(Me.LoginDataSet.details)
        End Sub
    End Class

    Business logic tier
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Security.Principal
    Imports System.Threading
    Imports System.IO
    Imports System.Text
    Namespace cbal
        Public Class bal
            Dim check As New dal.cdal
            Dim myDS As dal.cdal
            Dim loginattempts As Integer
            Public Function verify(ByVal use As String, ByVal pas As String) As String
                If (use.Length > 10) Then
                    Throw New Exception("username must be atleast 10 characters")
                ElseIf (pas.Length > 6) Then
                    Throw New Exception("password must be atleast 6 charcters long")
                End If
                loginattempts += 1
                If loginattempts >= 3 Then
                    MsgBox("Too many failed login attempts", MsgBoxStyle.Exclamation)
                Else
                    MsgBox("User Name not found.  Please try again", MsgBoxStyle.Exclamation)
                End If
                Return myDS
            End Function
        End Class
    End Namespace

    Data tier

    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Text
    Imports System.Security.Principal
    Imports System.Threading
    Imports System.IO
    Namespace dal
        Public Class cdal
            Dim strConnect As String = "Data Source=pc325;Initial Catalog=pubs;Integrated Security=SSPI;"
            Dim Con As SqlConnection = New SqlConnection(strConnect)
            Dim login As Object
            Dim mySDA As Object
            Dim myDS As Object
            Sub Main()
                Try
                    Con.Open()
                    Console.WriteLine("Connection Opened")
                Catch ex As SqlException
                    Console.WriteLine("Error: " & ex.ToString())
                Finally
                    Con.Close()
                    Console.WriteLine("Connection Closed")
                End Try
            End Sub
            Public Function check(ByVal use As String, ByVal pas As String)
                If (use = use And pas = pas) Then
                    Console.WriteLine("login success")
                Else
                    Console.WriteLine("Invalid name/password")
                End If
                Dim com As New SqlCommand("select * from details where use ='" & use & "'pas ='" & pas & "'", Con)
                Dim SqlDataAdapter As New mySDA
                Dim mySDA As New SqlDataAdapter(login)
                Dim DataSet As New myDS
                mySDA.Fill(myDS)        'cmdObj.Dispose()
                Con.Close()
                Return myDS
            End Function
            Private Sub SqlDataAdapter(ByVal p1 As Object)
                Throw New NotImplementedException
            End Sub
        End Class
    End Namespace


    I am getting the following error in the application tier:

    An error on line 19 that Class 'WindowsApplication2.bal.cbal' cannot be indexed because it has no default property.

    thanks in advance

    regards,

    badri

    Tuesday, August 31, 2010 4:57 AM
  •  
    

     

     app.conf
    <configuration>
    <configSections>
    </configSections>
    <connectionStrings>
    <add name="ConnectionString"
    connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DatabaseUits.mdf;Integrated Security=True;User Instance=True"
    providerName="System.Data.SqlClient" />
    </connectionStrings>
    </configuration>
    
    ----------------------------ClsConnection---------------------------------
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    namespace UIUITS
    {
    public class ClsConnection
    {
        DALUITS.ClsDataAccess da=new DALUITS.ClsDataAccess();
        private string _ConnectionString;
        public string ConnectionString
            {
            get { return _ConnectionString; }
            set { _ConnectionString = value; }
            }
        public ClsConnection()
            {
            ConnectionStringSettings ObjConnection=ConfigurationManager.ConnectionStrings["ConnectionString"];
            ConnectionString = ObjConnection.ConnectionString;
            }
        }
    }
    
    ------------DAL------------------ClsDataAccess-----------------------------------
    using System;
     using System.Collections.Generic;
     using System.Text;
     using System.Data;
     using System.Data.SqlClient;
     using System.Windows.Forms;
     using System.Configuration;
     namespace DALUITS
         {
         public class ClsDataAccess
             {
             //UIUITS.ClsConnection ObjCon
             #region Property
             public string _ConnectionString;
             private SqlConnection _Con;
             private SqlCommand _Cmd;
             private SqlDataAdapter _da;
             private SqlTransaction _trans;
             public string ConnectionString
                 {
                 get { return _ConnectionString; }
                 set { _ConnectionString = value; }
                 }
             public SqlConnection Con
                 {
                 get { return _Con; }
                 set { _Con = value; }
                 }
             public SqlCommand Cmd
                 {
                 get { return _Cmd; }
                 set { _Cmd = value; }
                 }
             public SqlDataAdapter da
                 {
                 get { return _da; }
                 set { _da = value; }
                 }
             public SqlTransaction trans
                 {
                 get { return _trans; }
                 set { _trans = value; }
                 }
             #endregion
             #region Method
             public void OpenConnection()
                 {
                 Con = ConnectionString;
                 if (Con.State != ConnectionState.Open)
                     {
                     Con.Open();
                     }
                 }
             public void CloseConnection()
                 {
                 if (Con != null)
                     {
                     Con.Close();
                     }
                 }
             public DataTable ExecuteDataAdapter(string Sql)
                 {
                 try
                     {
                     OpenConnection();
                     da = new SqlDataAdapter(Sql, Con);
                     DataTable dt = new DataTable();
                     da.Fill(dt);
                     da.Dispose();
                     return dt;
                     }
                     catch (Exception ex)
                     {
                         throw new Exception(ex.Message);
                         }
                     finally
                     {
                     CloseConnection();
                     }
                 }
             public void ExecuteNonQuerySp(String CommandTxt)
                 {
                 try
                     {
                     Cmd.Connection = Con;
                     Cmd.CommandType = CommandType.StoredProcedure;
                     Cmd.CommandText = CommandTxt;
                     Cmd.ExecuteNonQuery();
                     Cmd.Dispose();
                     }
                     catch (Exception ex)
                     {
                         throw new Exception(ex.Message);
                         }
                     finally
                     {
                     CloseConnection();
                     }
                 }
             #endregion
             public void transctionFun()
                 {
                 Con.ConnectionString = Con;
                 Con.Open();
                 trans = Con.BeginTransaction();
                 try
                     {
                     string qury;
                     qury = "select getdate()";
                     Cmd.Connection = Con;
                     Cmd.Transaction = trans;
                     Cmd.CommandType = CommandType.StoredProcedure;//CommandType .TableDirect //CommandType.Text;
                     Cmd.CommandTimeout = 10;
                     Cmd.ExecuteNonQuery();
                     DataTable dt;
                     if (dt.Rows.Count > 0)
                         {
                         qury = "";
                         qury ="Insert timeout()";
                         }
                     trans.Commit();
                     }
                     catch
                     {
                            trans.Rollback();
                     }
                    finally
                     {
                     trans.Save();
                     trans.Dispose();
                     }
                 }
             public void BeginTrans()
                 {
                 try
                     {
                     if (con != null)
                         {
                         Mytrans = con.beginTransaction();
                         }
                     }
                     catch
                     {
                     }
                 }
             public void CommitTrans()
                 {
                 try
                     {
                     if (con != null)
                         {
                         Mytrans.Commit();
                         }
                     }
                     catch
                     {
                         }
                 }
             public void RollBackTrans()
                 try
             {
             if (con != null)
             {
             Mytrans.RollBack();
             }
         }
    catch
    {
    }
    }
    }
    }
    -------DAL----------------------ClsRegistration--------------------------------------
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Configuration;
    namespace DALUITS
    {
    public class ClsRegistration
    {
    #region Property
    private int _Mode;
    private string _ConnectionString;
    private int _UserName;
    private string _UserPassword;
    public int Mode
    {
        get { return _Mode; }
        set { _Mode = value; }
    }
    public string ConnectionString
    {
        get { return _ConnectionString; }
        set { _ConnectionString = value; }
    }
    public int UserName
    {
        get { return _UserName; }
        set { _UserName = value; }
    }
    public string UserPassword
    {
        get { return _UserPassword; }
        set { _UserPassword = value; }
    }
    #endregion
    
    #region Inisilization
    public ClsRegistration()
    {
        Mode = 0;
        ConnectionString = string.Empty;
        UserName = 0;
        UserPassword = string.Empty;
    }
    public ClsRegistration(string ConnectionString)
    {
        Mode = 0;
        ConnectionString = string.Empty;
        UserName = 0;
        UserPassword = string.Empty;
    }
    #endregion
    
    public void CreateRegistration()
    {
        DALUITS.ClsDataAccess ObjDa = new ClsDataAccess();
        ObjDa.ConnectionString = ConnectionString;
        ObjDa.OpenConnection();
        ObjDa.Cmd = new SqlCommand();
        ObjDa.Cmd.Parameters.AddWithValue("@UserName", UserName);
        ObjDa.Cmd.Parameters.AddWithValue("@UserPassword", UserPassword);
        ObjDa.ExecuteNonQuerySp("SpInsRegTab");
        ObjDa.Cmd.Dispose();
        ObjDa.CloseConnection();
    }
    }
    }
    
     --------------BAL----------------------------ClsRegistration------------------------
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    namespace BLLUITS
    {
    public class ClsRegistration
    {
    #region Property
    private int _Mode;
    private string _ConnectionString;
    private int _UserName;
    private string _UserPassword;
    public int Mode
    {
        get { return _Mode; }
        set { _Mode = value; }
    }
    public string ConnectionString
    {
        get { return _ConnectionString; }
        set { _ConnectionString = value; }
    }
    public int UserName
    {
        get { return _UserName; }
        set { _UserName = value; }
    }
    public string UserPassword
    {
        get { return _UserPassword; }
        set { _UserPassword = value; }
    }
    #endregion
    
    #region Inisilization
    public ClsRegistration()
    {
        Mode = 0;
        ConnectionString = string.Empty;
        UserName = 0;
        UserPassword = string.Empty;
    }
    public ClsRegistration(string ConnectionString)
    {
        Mode = 0;
        ConnectionString = string.Empty;
        UserName = 0;
        UserPassword = string.Empty;
    }
    #endregion
    
    #region
    public void CreateRegistration()
    {
        DALUITS.ClsRegistration ObjReg = new DALUITS.ClsRegistration();
        ObjReg.ConnectionString = ConnectionString;
        ObjReg.UserName = UserName;
        ObjReg.UserPassword = UserPassword;
        ObjReg.CreateRegistration();
    }
    #endregion
    }
    
     ------------------Client Event(Button Click)--------------------FrmUserRegistraton -----------------------
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    namespace UIUITS
    {
        public partial class FrmUserRegistraton : Form
        {
            public FrmUserRegistraton()
            {
            InitializeComponent();
            }
            private void FrmUserRegistraton_Load(object sender, EventArgs e)
            {
            }
            private void button2_Click(object sender, EventArgs e)
            {
                BLLUITS.ClsRegistration ObjReg = new BLLUITS.ClsRegistration();
                ObjReg.UserName = Convert.ToInt32(textBox1.Text);
                ObjReg.UserPassword = textBox2.Text.ToString();
                ObjReg.CreateRegistration();
            }
        }
    



    Kamal Saxena iBOOK dESK (UITS INDIA)


    • Edited by UITS INDIA Thursday, November 10, 2011 5:42 PM
    Thursday, November 10, 2011 5:24 PM
  • Hello,

    i need some sample examples xplaining about 3 tier...plz provide me some links explaining 3 tier thru source code..

    By tier I think you might mean logical 'layer', but regardless here is some help for both scenarios.  A traditional 3-layer application consists of a UI (or Presentation) layer, the Busniess Logic Layer, and the Data Access Layer.  These are 'logical' layers that could actually exist all on a single server.  When you being separating layers onto thier own machines, that is when they become 'tiers'.  Adding tiers to an architecture is much more expensive than adding layers in general due to the extra domain calls required.

    Here are some links that might help you understand some more in depth including code examples:

    Building an N-Tier Application in .NET: 

    http://msdn.microsoft.com/en-us/library/ms973279.aspx

    Creating a UI-BLL-DAL:

    http://www.asp.net/data-access/tutorials/introduction

    N-Layered Web Applications with ASP.NET 3.5 Part 1: General Introduction:

    http://imar.spaanjaars.com/476/n-layered-web-applications-with-aspnet-35-part-1-general-introduction

    3-tier Architecture with ASP.NET 2.0:

    http://msdn.microsoft.com/en-us/library/aa581769.aspx

    Next, to help with understanding the difference between tiers and layers.  The following links will help with this:

    Should all apps be n-tier?

    http://www.lhotka.net/WeBlog/PermaLink.aspx?guid=efa88d0a-2388-4909-bee1-c9bddb6e9868

    A variety of physical n-tier options:

    http://www.lhotka.net/weblog/AVarietyOfPhysicalNtierOptions.aspx

    Hope this helps!


    • Edited by atconway Monday, November 14, 2011 2:13 PM
    Monday, November 14, 2011 2:12 PM