0 Replies Latest reply on Jan 31, 2009 11:37 PM by mtgna

    Problem with SQL Insert

    mtgna Level 1
      Hi

      I am using Flex to insert data through remoteobject and using SAVE method generated from CFC Wizard.
      My VO contains the following variables where id has a default value of 0 :
      public var id:Number = 0 ;
      public var date:String = "";
      public var accountno:String = "";
      public var debit:Number = 0;
      public var credit:Number = 0;
      id is set as the primary key in my database.
      I have previously used MySQL which automatically generates a new id if I either omitted the id value in my insert statement or use 0 as the default value.
      However, now I am using MS SQL Server and the insert generated this error:

      Unable to invoke CFC - Error Executing Database Query.

      Detail:
      [Macromedia][SQLServer JDBC Driver][SQLServer]Cannot insert explicit value for identity column in table 'Transactions' when IDENTITY_INSERT is set to OFF.

      Strange thing is that I dont see this problem with another sample application. I compared with that application (it has the same VO with default value of 0 for id) and everything looks similar so I can't understand why I have this error in my application.

      This is SQL used to create the table:

      USE [Transactions]
      SET ANSI_NULLS ON
      SET QUOTED_IDENTIFIER ON
      SET ANSI_PADDING ON

      CREATE TABLE [dbo].[Transactions](
      [id] [int] IDENTITY(1,1) NOT NULL,
      [date] [datetime] NULL,
      [accountno] [varchar](100) NULL,
      [debit] [int] NULL,
      [credit] [int] NULL,

      CONSTRAINT [PK_Transactions] PRIMARY KEY CLUSTERED
      (
      [id] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE =
      OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
      ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
      ) ON [PRIMARY]



      Has anyone encountered this problem before with insert statements dealing with a unique id (with MS SQL Server)?