0

I am generating a SqlException in two procedures.

Both the procedures are called within the same try catch block depending upon a condition (either is called at a time).

For one procedure both the errors are being caught in the correct catch. For the second procedure call.. it says SqlException unhandled by usercode.

    protected void btnAdd_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            ALN_VM_Cust ObjCust = new ALN_VM_Cust();
            IManageVM objImanageVM = new ALN_VM_Rep();
            ALN_VM_BOL ObjBOL = new ALN_VM_BOL(objImanageVM);

            ObjCust.VMName = txtVMName.Text;
            if(txtDescription.Value=="")
                Response.Write("<script langauge=\"javascript\">alert(\"Please enter the description for configuration\");</script>");
            ObjCust.VMDescription = Server.HtmlEncode(txtDescription.Value);
            ObjCust.CreatedBy = Session["UserAccentureID"].ToString();
            ObjCust.VMConfig = Convert.ToInt32(ddlVMConfig.SelectedValue);
            ObjCust.VMCost =Convert.ToDouble( txtCost.Text);
            ObjCust.Comment = Server.HtmlEncode(txtComment.Value);


            if (ViewState["Mode"].ToString() == "Edit")
            {
                ObjCust.ModifiedBy = Session["UserAccentureID"].ToString();
                ObjCust.VMId = Convert.ToInt32(ViewState["VMID"].ToString());
                ObjCust.CommandType = "U";

                    string strResult = ObjBOL.UpdateVMDetails(ObjCust);
                    if (strResult == "Success")
                    {
                        ALNMessageHandler.LogEvent("VM details updated successfully", true, "VM updated");
                        BindGrid();
                        ClearFields();
                    }
                }
            }
            else
            {
                string Result = ObjBOL.InsertVMDetails(ObjCust);
                if (Result == "Success")
                {
                    ALNMessageHandler.LogEvent("VM details saved successfully", true, "VM created");
                    ClearFields();
                    ViewState["Mode"] = "Add";
                    BindGrid();
                }
            }
        }
        catch (Exception ex)
        {
            if (ex.Message.ToString().ToUpper() == "VM NAME ALREADY EXIST.")
            {
                AlnErrorHandler.DisplayError(ex.Message);
            }

            if (ex.Message.ToString() == "Total VM cost exceeds 3000$.")
            {
                AlnErrorHandler.DisplayError(ex.Message);
            }

            //if (ex.Message.ToString().Contains("VM cannot be currently deleted") == true)
            if (ex.Message.ToString() == "VM cannot be currently deleted") 
            {
                AlnErrorHandler.DisplayError(ex.Message);
            }
        }
    }

The procedure call in another project's call..

    public string UpdateVMDetails(ALN_VM_Cust objCust)
    {
        try
        {
            SqlParameter[] storedParams = new SqlParameter[7];
            storedParams[0] = new SqlParameter("@VMId", SqlDbType.VarChar);
            storedParams[0].Value = objCust.VMId;

            storedParams[1] = new SqlParameter("@VMName", SqlDbType.VarChar);
            storedParams[1].Value = objCust.VMName;

            storedParams[2] = new SqlParameter("@ModifiedBy", SqlDbType.VarChar);
            storedParams[2].Value = objCust.ModifiedBy;

            storedParams[3] = new SqlParameter("@VMDescription", SqlDbType.VarChar);
            storedParams[3].Value = objCust.VMDescription;

            storedParams[4] = new SqlParameter("@CommandType", SqlDbType.VarChar);
            storedParams[4].Value = objCust.CommandType;

            storedParams[5] = new SqlParameter("@VMCost", SqlDbType.Float);
            storedParams[5].Value = objCust.VMCost;

            storedParams[6] = new SqlParameter("@Comment", SqlDbType.VarChar);
            storedParams[6].Value = objCust.Comment;

            DataSet ds = SqlHelper.ExecuteDataset(ALNConnection, CommandType.StoredProcedure, "VM_UpdateVMDetails", storedParams);

            return "Success";
        }
        catch (SqlException exSQL)
        {
            throw exSQL;
        }
        catch (Exception exError)
        {
            throw exError;
        }
    }

It goes in last catch in the above quoted function of other class

Where am I going wrong?

4

0 回答 0