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.
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.
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.
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_2AF7AF 2B05834382 AAD04F7689 7941BE] 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.Sq lCeCommand
Me._adapter.InsertCommand. Connection = Me.Connection
Me._adapter.InsertCommand. CommandTex t = "INSERT INTO [Town] ([Town_cd], [TownName], [TownState]) VALUES (@p1, @p2, @p3)"
Me._adapter.InsertCommand. CommandTyp e = System.Data.CommandType.Te xt
param = New System.Data.SqlServerCe.Sq lCeParamet er
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.Sq lCeParamet er
param.ParameterName = "@p2"
param.IsNullable = true
param.SourceColumn = "TownName"
Me._adapter.InsertCommand. Parameters .Add(param )
param = New System.Data.SqlServerCe.Sq lCeParamet er
param.ParameterName = "@p3"
param.DbType = System.Data.DbType.StringF ixedLength
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 TownBindingNavigatorSaveIt em_Click(B yVal sender As System.Object, ByVal e As System.EventArgs) Handles TownBindingNavigatorSaveIt em.Click
Me.Validate()
Me.TownBindingSource.EndEd it()
Me.TownTableAdapter.Update (Me.UPC_Mo bileDataSe t.Town)
End Sub
The exception occurs in the EndEdit method.
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_
[TownState] [nchar](2) COLLATE SQL_Latin1_General_CP1_CI_
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [MSmerge_df_rowguid_2AF7AF
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.Sq
Me._adapter.InsertCommand.
Me._adapter.InsertCommand.
Me._adapter.InsertCommand.
param = New System.Data.SqlServerCe.Sq
param.ParameterName = "@p1"
param.DbType = System.Data.DbType.Int32
param.IsNullable = true
param.SourceColumn = "Town_cd"
Me._adapter.InsertCommand.
param = New System.Data.SqlServerCe.Sq
param.ParameterName = "@p2"
param.IsNullable = true
param.SourceColumn = "TownName"
Me._adapter.InsertCommand.
param = New System.Data.SqlServerCe.Sq
param.ParameterName = "@p3"
param.DbType = System.Data.DbType.StringF
param.IsNullable = true
param.SourceColumn = "TownState"
Me._adapter.InsertCommand.
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 TownBindingNavigatorSaveIt
Me.Validate()
Me.TownBindingSource.EndEd
Me.TownTableAdapter.Update
End Sub
The exception occurs in the EndEdit method.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.