R – ADO.NET Service update error

wcf-data-services

I have a very simple exercise on ADO.NET Service: Put the list of Product in a list box, when selection changed in the list box, display UnitPrice and UnitInStock in two textboxes.
Then change the data in textboxes and save the changes.

Here is all code for at client side:

namespace TestApp
{
    public partial class Form1 : Form
    {
        NorthwindDataContext ctx = new NorthwindDataContext(new Uri("http://localhost:3540/Northwind.svc/"));
        public Form1()
        {
            InitializeComponent();
            var q = from p in ctx.Products
                    select p;
            listBox1.DataSource = q.ToList();
            listBox1.DisplayMember = "ProductName";
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var p = listBox1.SelectedItem as Product;
            textBox1.Text = p.UnitPrice.ToString();
            textBox2.Text = p.UnitsInStock.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {    
            var p = listBox1.SelectedItem as Product;
            p.UnitPrice = Decimal.Parse(textBox1.Text);
            p.UnitsInStock = short.Parse(textBox2.Text);
            try
            {
                //ctx.AttachTo("Products", p);
                //ctx.BeginSaveChanges();
                ctx.UpdateObject(p);
                ctx.SaveChanges(SaveChangesOptions.None);
            }
            catch (Exception ex)
            {
                label3.Text = ex.Message;
            }
        }
    }
}

The ADO.NET Service is fine and its permission set as:

 config.SetEntitySetAccessRule("*", EntitySetRights.All);

When I hit the save button, I got error message as:
ex.Message = "An error occurred while processing this request."

Not sure why. please help.

Best Answer

please on your service turn on the UserVerboseErrors

config.UseVerboseErrors = true;

And it would be helpful to override the method handleexception

protected override void HandleException(HandleExceptionArgs args)

After you have done that let us know what the error is.