Throw exception in DataPortal_Insert method

Throw exception in DataPortal_Insert method

Old forum URL: forums.lhotka.net/forums/t/3739.aspx


rjsjng posted on Thursday, October 18, 2007

Hi,
    I am new to CSLA. I have a query.
   How can I throw an exception in DataPortal_Insert method. I have try to thrown an exception in DataPortal_Insert Method but I cann't receive that error at Save Method. I got the DataPortal.Update failed error message.

[Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Insert()
        {
            using (SqlConnection Sqlcon = new SqlConnection(DBClient.EmpDBConnectionString))
            {
                Sqlcon.Open();
                using (SqlCommand cm = Sqlcon.CreateCommand())
                {
                    cm.CommandType = CommandType.StoredProcedure;
                    cm.CommandText = "EmployeeProc";
                    try
                    {
                        cm.ExecuteNonQuery();
                    }
                    catch (SqlException exp)
                    {
                        throw exp;
                    }
                }
            }
        }

      Code In aspx.cs File:

        try
        {
            Employee obj = employee.Save();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            Console.WriteLine(ex.Message);
        }

Please advise.

Thanks,
rjs


ajj3085 replied on Thursday, October 18, 2007

Any exception thrown in a DP_xyz method will be wrapped in a Csla.DataPortalException.  You'll need to catch that, and inspect the BusinessException it contains. 

HTH
Andy

rjsjng replied on Thursday, October 18, 2007

Thank you  Andy,
rjs

Copyright (c) Marimer LLC