0 Replies Latest reply on Sep 3, 2008 12:11 PM by EvolvedDSM

    Getting this error: "Item with id '0' already exists.  Error on destination 'myds'"

    EvolvedDSM Level 2
      Error:
      Item with id '0' already exists. Error on destination 'myds'
      Set up:
      Flex web app using FDS connected to an MS-SQL db ColdFusion Datasource.
      Occurs when:
      Attempting to add more than one record from a form in my app.

      The database is MS-SQL using an auto-increment (identity=yes) numeric primary key (which is where the problem lies I think). I've never had this problem using MS access databases and I'm using the same Flex code for both. I'm connecting to the datasource with the CFC wizard from RDS in Flex. I use the same method as my MS Access db's which have never caused this error. I suspect that either a CFC or the action script class is not handling the increment of the SQL db after an entry is created.

      import mx.data.DataService;
      import mx.collections.ArrayCollection;
      import valueObjects.asObject;

      private var ds:DataService;
      [Bindable]
      private var ac:ArrayCollection;
      private var myObject:asObject;

      initApp():void{
      ds = new DataService("myds");
      ac = new ArrayCollection();
      ds.fill(ac);
      }

      createEntry():void{
      myObject = new asObject;
      myObject.col1 = field1.text;
      myObject.col2 = field2.text;
      myObject.col3 = field3.text;
      ds.createItem(myObject);
      }
      There's a form with field1, 2, 3 and a button that calls createEntry()

      Creating the first entry is fine. The database inserts the new item and the datagrid immediately displays the addition. Trying to create another entry give the error above. There's something wrong with the way the CFC or something is handling the primary key.

      If no one can figure this out, can someone post a method of how I can code auto-increment to a CFC? I'll just make my primary key non-increment if I can do this. thanks