none
Cannot add a new record to a db handled by a WCFservice RRS feed

  • Question

  • I'm working with VS 2010.   Have a Windows forms application that connects to WCF Service.   Everything seems to work fine except when I try to add a new record.   I can read and update the database fine, only adding a new record fails like with below code.    I get an execption thrown. See the exception further below.

    internal bool registerProduct(string fname, string lname, string service, string model, string email, string telnumber, DateTime regdate, string purchase, 
                string notify, string recoverycode, string SQ, string ATSQ, string paymethod, string cctype, string ccnumber, short locks)
            {
                // Create the new user data.
                DDSServiceReference.UserData ud = DDSServiceReference.UserData.CreateUserData( 0, service, model); // add the non nullable values
                // set other property values
                ud.FirstName = fname;
                ud.LastName = lname;
                ud.email = email;
                ud.TelNumber = telnumber;
                ud.RegistrationDate = regdate;
                ud.Purchased = purchase;
                ud.NotifyMethod = notify;
                ud.RecoveryCode = "";
                ud.SQ = SQ;
                ud.ATSQ = ATSQ;
                ud.PayMethod = paymethod;
                ud.CCType = cctype;
                ud.CCNumber = "ccnumber";
                ud.LockInstances = 2;
    
                try
                {
                    // Add the new userdata to the UserDatas entity set.
                    proxy.AddToUserDatas(ud);
                    
                    DataServiceResponse response = proxy.SaveChanges();
                    foreach (ChangeOperationResponse change in response)
                    {
                        // Get the descriptor for the entity.
                        EntityDescriptor descriptor = change.Descriptor as EntityDescriptor;
                        if (descriptor != null)
                        {
                            DDSServiceReference.UserData addedUseData = descriptor.Entity as DDSServiceReference.UserData;
    
                            if (addedUseData != null)
                            {
                                Console.WriteLine("New user added with ID {0}.", addedUseData.ServiceTag);
                            }
                        }
                    } 
                    return true;
                }
                catch (DataServiceRequestException ex)
                {
                    throw new ApplicationException(
                        "An error occurred when saving record.", ex);
                }
    
            }
    System.ApplicationException was unhandled
      HResult=-2146232832
      Message=An error occurred when saving record.
      Source=DDSClient
      StackTrace:
           at DDSClient.DataExchange.registerProduct(String fname, String lname, String service, String model, String email, String telnumber, DateTime regdate, String purchase, String notify, String recoverycode, String SQ, String ATSQ, String paymethod, String cctype, String ccnumber, Int16 locks) in C:\AppPractice\DDSClient\DataExchange.cs:line 104
           at DDSClient.Form1.button1_Click(Object sender, EventArgs e) in C:\AppPractice\DDSClient\Form1.cs:line 38
           at System.Windows.Forms.Control.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ButtonBase.WndProc(Message& m)
           at System.Windows.Forms.Button.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(Form mainForm)
           at DDSClient.Program.Main() in C:\AppPractice\DDSClient\Program.cs:line 18
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.Data.Services.Client.DataServiceRequestException
           HResult=-2146233079
           Message=An error occurred while processing this request.
           Source=System.Data.Services.Client
           StackTrace:
                at System.Data.Services.Client.DataServiceContext.SaveResult.HandleBatchResponse()
                at System.Data.Services.Client.DataServiceContext.SaveResult.EndRequest()
                at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
                at System.Data.Services.Client.DataServiceContext.SaveChanges()
                at DDSClient.DataExchange.registerProduct(String fname, String lname, String service, String model, String email, String telnumber, DateTime regdate, String purchase, String notify, String recoverycode, String SQ, String ATSQ, String paymethod, String cctype, String ccnumber, Int16 locks) in C:\AppPractice\DDSClient\DataExchange.cs:line 84
           InnerException: System.Data.Services.Client.DataServiceClientException
                HResult=-2146233079
                Message=<?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
      <code></code>
      <message xml:lang="en-US">An error occurred while processing this request.</message>
    </error>
                Source=System.Data.Services.Client
                StatusCode=500
                StackTrace:
                     at System.Data.Services.Client.DataServiceContext.SaveResult.<HandleBatchResponse>d__1e.MoveNext()
                InnerException:

    NR

    Thursday, December 27, 2012 10:48 PM

Answers

  • I finally resolved this problem and I'dlike to bang my head against the wall after I resolved it.  I spent two days on this convinced that it was a service problem.  The problem turned out to be a comboBox which had an Item that it was 11 characters long when the SQL field specified only 10 characters.  Shrank the entry to 10 characters and everything worked fine.

    The moral of this, never assume the more complex until you have checked the easy and common stuff first.


    NR

    • Marked as answer by Highlander4 Saturday, December 29, 2012 1:55 AM
    Saturday, December 29, 2012 1:55 AM

All replies

  • hello,

    From your code, it seems that it failed at MoveNext() method.

    Check the WCF service method for detailed.

    Best regards,


    Ghost,
    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Friday, December 28, 2012 9:10 AM
  • There is no MoveNext() method in the entire solution.  Perhaps in hidden code in the entity engine, however, I did a search on the entire solution and there is no such thing.  I have gone thru the entire solution to make sure that none of the data types have changed and everything looks normal.  The service entity has all rights assigned, updates work fine but not the adding. 

    NR

    Friday, December 28, 2012 7:03 PM
  • Ok its defintely not the service.  I used the same method  to add the record, but this time I just passed simple string variables to the method to fill the properties and it worked just fine.   The problem seems to be when I pass the parameters to the method from a bunch of textboxes I have on a form to emulate user entries.  I have looked at their values by now a hundred times I can't seem to find what's causing it.    I'll look again, it has to be a transaltion problem from the Form to the Product registration method.   Will let you know when I find it.

    NR

    • Marked as answer by Highlander4 Saturday, December 29, 2012 1:48 AM
    • Unmarked as answer by Highlander4 Saturday, December 29, 2012 1:49 AM
    Friday, December 28, 2012 8:44 PM
  • I finally resolved this problem and I'dlike to bang my head against the wall after I resolved it.  I spent two days on this convinced that it was a service problem.  The problem turned out to be a comboBox which had an Item that it was 11 characters long when the SQL field specified only 10 characters.  Shrank the entry to 10 characters and everything worked fine.

    The moral of this, never assume the more complex until you have checked the easy and common stuff first.


    NR

    • Marked as answer by Highlander4 Saturday, December 29, 2012 1:55 AM
    Saturday, December 29, 2012 1:55 AM