Link to home
Start Free TrialLog in
Avatar of bobgilpin
bobgilpin

asked on

"Column 'rowguid' does not allow nulls."

I have replicated a database to SQL Server Mobile.  The publication automatically created rowguid columns for each article.  The Merge replication synchronizes fine for updates to rows, but when I try to add a new row to the mobile database I get the error "Column 'rowguid' does not allow nulls." upon saving the row.  The rowguid column is defined with the default value "(newsequentialid())"  Thanks for any help you can give.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

can you show the code that performs the INSET?
If you have an insert statement like this:

INSERT INTO [MyTable] ([PKColumn], [OtherColumn]) VALUES (NULL, 'some data')

it will actually try to put a null in the not-nullable column.  What you want it this:

INSERT INTO [MyTable] ([OtherColumn]) VALUES ('some data')

That will use the default value and create the new id.
Avatar of bobgilpin
bobgilpin

ASKER

I didn't mention the application is VB 2005 as a VS 2005 project.  I have a simple windows form with a table adapter that contains the SQL commands for select, update and insert.  

This is the table definition (from SQL server):
CREATE TABLE [dbo].[Town](
      [TownCode] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
      [Town_cd] [int] NULL,
      [TownName] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [TownState] [nchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [MSmerge_df_rowguid_2AF7AF2B05834382AAD04F76897941BE]  DEFAULT (newsequentialid()),
 CONSTRAINT [PK_Town] PRIMARY KEY CLUSTERED
(
      [TownCode] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

This is the VB code for the Insert command:
            Me._adapter.InsertCommand = New System.Data.SqlServerCe.SqlCeCommand
            Me._adapter.InsertCommand.Connection = Me.Connection
            Me._adapter.InsertCommand.CommandText = "INSERT INTO [Town] ([Town_cd], [TownName], [TownState]) VALUES (@p1, @p2, @p3)"
            Me._adapter.InsertCommand.CommandType = System.Data.CommandType.Text
            param = New System.Data.SqlServerCe.SqlCeParameter
            param.ParameterName = "@p1"
            param.DbType = System.Data.DbType.Int32
            param.IsNullable = true
            param.SourceColumn = "Town_cd"
            Me._adapter.InsertCommand.Parameters.Add(param)
            param = New System.Data.SqlServerCe.SqlCeParameter
            param.ParameterName = "@p2"
            param.IsNullable = true
            param.SourceColumn = "TownName"
            Me._adapter.InsertCommand.Parameters.Add(param)
            param = New System.Data.SqlServerCe.SqlCeParameter
            param.ParameterName = "@p3"
            param.DbType = System.Data.DbType.StringFixedLength
            param.IsNullable = true
            param.SourceColumn = "TownState"
            Me._adapter.InsertCommand.Parameters.Add(param)

This command works fine when run in a query window in VS 2005:
INSERT INTO Town
                      (Town_cd, TownName, TownState)
VALUES     (1234, 'Jamestown', 'NY')

The problem occurs when I click the Save button on the Binding Navigator on my form for a new row.
This is the code for that button:
Private Sub TownBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TownBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TownBindingSource.EndEdit()
        Me.TownTableAdapter.Update(Me.UPC_MobileDataSet.Town)

End Sub

The exception occurs in the EndEdit method.
ASKER CERTIFIED SOLUTION
Avatar of bobgilpin
bobgilpin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial