Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have text file with fixed length data text file line is

07010001090560000201711061250160000472100100000001090560298609999MMBSLR/2017000063/SBP/BI-MUAJJAL SLR ACC                                       000002017000063PKR10000000062872.16001.000000000000000062872.16OBBBBRRRRSDDDDDDDDVTTTTTTIQQQ00
"


I have a model class where we have setter and setters for model.

namespace Model
{
   public class FileData
    {
 private string _Transaction_ID;

   public String Transaction_ID
        {
            get
            {
                return _Transaction_ID;
            }
            set
            {
                _Transaction_ID= value;
            }
        }


}


  public bool Save(Model.IBRFileData FileData)
        {
            this._Sql.AddInParameter(command, PARAM_Transation_ID, DbType.String, FileData.Transation_ID, 
           
          

            #endregion

            try
            {
                this._Sql.ExecuteNonQuery(command);
                retunval = true;
            }
            catch (Exception ex)
            {
               
                

              log error  to database

                retunval = false;
            }

            return retunval;

        }


File Data is inserted into database using DAL . question here is from interface when file data is inserted into database using DAL if unique constraint error occurred
then where should i log this exception ? i want to make a log of exception for every row which is inserted n db and get error.

where should i write a code for exception logging in DAL or in code behind where data is inserted one by one through loop?

What I have tried:

i have text file with fixed length data text file line is

<pre>07010001090560000201711061250160000472100100000001090560298609999MMBSLR/2017000063/SBP/BI-MUAJJAL SLR ACC                                       000002017000063PKR10000000062872.16001.000000000000000062872.16OBBBBRRRRSDDDDDDDDVTTTTTTIQQQ00
"


I have a model class where we have setter and setters for model.

namespace Model
{
   public class FileData
    {
 private string _Transaction_ID;

   public String Transaction_ID
        {
            get
            {
                return _Transaction_ID;
            }
            set
            {
                _Transaction_ID= value;
            }
        }


}


  public bool Save(Model.IBRFileData FileData)
        {
            this._Sql.AddInParameter(command, PARAM_Transation_ID, DbType.String, FileData.Transation_ID, 
           
          

            #endregion

            try
            {
                this._Sql.ExecuteNonQuery(command);
                retunval = true;
            }
            catch (Exception ex)
            {
               
                

              log error  to database

                retunval = false;
            }

            return retunval;

        }


File Data is inserted into database using DAL . question here is from interface when file data is inserted into database using DAL if unique constraint error occurred
then where should i log this exception ? i want to make a log of exception for every row which is inserted n db and get error.

where should i write a code for exception logging in DAL or in code behind where data is inserted one by one through loop?
Posted
Comments
Sinisa Hajnal 30-Nov-17 6:30am    
You catch exception as early as you can and log it (in this case in DAL). In case you need to inform the user, you bubble the exception up to UI (AFTER logging it). UI should catch the exception and show suitable user friendly error. You could for example log original error in DAL, catch the exception again in business logic and create ApplicationException with custom (and maybe localized ) error message. Finally, you catch it in UI and show the message to the user

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