-5

HI i am using 3 tire architecture for my project i am getting follpwing error : An unhandled exception of type '

namespace Dal_AddTranction
{
    public class Add_Trancation_Dal
    {

        Add_Tranction_UI ObjAdd = new Add_Tranction_UI();
        Add_Tranction_Bal objAddBal = new Add_Tranction_Bal();

        string cs = ConfigurationManager.ConnectionStrings["adesh"].ConnectionString;

        public Add_Trancation_Dal()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public void Add_Tranction(DateTime Date, string Particuler, decimal Price)
        {
            using (SqlConnection connection = new SqlConnection(cs))
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("Asp_Add_Tranction", connection);
                cmd.CommandType = CommandType.StoredProcedure;
                try
                {
                    cmd.Parameters.AddWithValue("@Date",Date);
                    cmd.Parameters.AddWithValue("@Particulare", Particuler);
                    cmd.Parameters.AddWithValue("@Price", Price);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    throw ex;

                }

            }
        }
    }
}

gives An unhandled exception of type 'System.StackOverflowException' occurred in App_Code.hup8rwkz.dll

Here are the Add_Tranction_UI and Add_Tranction_Bal classes:

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;
        using Dal_AddTranction;
        using Bal_AddTranction;

        /// <summary>
        /// Summary description for Add_Tranction_UI
        /// </summary>
        /// 

        namespace UI_AddTranction
        {
            public class Add_Tranction_UI
            {
                public Add_Tranction_UI()
                {
                    //
                    // TODO: Add constructor logic here
                    //
                }

                private DateTime _date;
                public DateTime date
                {
                    get
                    {
                        return _date;
                    }
                    set
                    {
                        _date = value;
                    }
                }
                private string _Particuler;
                public string Particuler
                {
                    get
                    {
                        return _Particuler;
                    }
                    set
                    {
                        _Particuler = value;
                    }
                }
                private decimal _Price;
                public decimal Price
                {
                    get
                    {
                        return _Price;


                    }
                    set
                    {
                        _Price = value;
                    }
                }




            }
        }


    ***Bal***



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Dal_AddTranction;
    using UI_AddTranction;

    /// <summary>
    /// Summary description for Add_Tranction_Bal
    /// </summary>
    /// 
    namespace Bal_AddTranction
    {
        public class Add_Tranction_Bal
        {


            Add_Trancation_Dal objAddDal = new Add_Trancation_Dal();
            public Add_Tranction_Bal()
            {
                //
                // TODO: Add constructor logic here
                //
            }

            public void Add_Tranction(Add_Tranction_UI objAddUI)
            {
                objAddDal.Add_Tranction(objAddUI);
            }
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dal_AddTranction;
using UI_AddTranction;
using Bal_AddTranction;

public partial class Daily_ADD_Tranction : System.Web.UI.Page
{
    Add_Tranction_UI objAddUI = new Add_Tranction_UI();
    Add_Tranction_Bal objAddBal = new Add_Tranction_Bal();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void imgDate_Click(object sender, ImageClickEventArgs e)
    {
        if (clddate.Visible == true)
        {
            clddate.Visible = false;

        }
        else
        {
            clddate.Visible = true;
        }
    }
    protected void clddate_SelectionChanged(object sender, EventArgs e)
    {
        txtDate.Text = clddate.SelectedDate.ToShortDateString();
        clddate.Visible = false;
    }


    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Add_Tranction();

        lblMesssage.Text = "Trancation Added Sucessfully";
    }


    public void Add_Tranction()
    {
        try
        {
            objAddUI.date = Convert.ToDateTime(txtDate.Text);
            objAddUI.Particuler = Convert.ToString(txtParticuler.Text);
            objAddUI.Price = Convert.ToDecimal(txtPrice.Text);
            objAddBal.Add_Tranction(objAddUI);



        }

        catch (Exception ex)
        {
            throw ex;
        }
    }
}
Grant Winney
  • 65,241
  • 13
  • 115
  • 165
Adesh Gaonkar
  • 31
  • 1
  • 1
  • 12

1 Answers1

1

Your DAL class creates an instance of your BAL class, which then creates an instance of your DAL class, in a continuous loop, until you blow up with a StackOverflowException.

You're not using those two instances anyway (nor should you be), so delete them.

public class Add_Trancation_Dal
{
    Add_Tranction_UI ObjAdd = new Add_Tranction_UI();       // DELETE THIS
    Add_Tranction_Bal objAddBal = new Add_Tranction_Bal();  // DELETE THIS TOO
    ...

public class Add_Tranction_Bal
{
    Add_Trancation_Dal objAddDal = new Add_Trancation_Dal();
    ...
Grant Winney
  • 65,241
  • 13
  • 115
  • 165