Wednesday, March 7, 2012

RDA Push with Identity column

Hi Everyone:

I am new to Mobile programming. I am now working on a small mobile app.

I encounter an issue when I sync the data:

Using RDA Pull, I can create the database and populate my table fine on my pocket pc device.

After updating the data on the device, I encounter an error when I try to Push my table back to the back-end SQL Server 2005 DB.

Error: "The identity range was not established."

VB CODE:
Private Sub RdaConnKeyHeaderPush()

Dim RemoteAccess As New Data.SqlServerCe.SqlCeRemoteDataAccess
Dim RDAConnectingString As String
RemoteAccess.InternetLogin = "<mylogin>"
RemoteAccess.InternetPassword = "<mypassword>"
RDAConnectingString = "Provider=SQLOLEDB;Persist Security Info=True;Data Source=<MySQLServer>;Initial Catalog=MobileKeyDB;" & _
"User ID=MobileUser;Password=<mypassword>"
RemoteAccess.InternetUrl = "https://www.<mysite>.com/SQLMobile/sqlcesa30.dll"
RemoteAccess.LocalConnectionString = "Data Source=Program Files\SQL Mobile\en\MobileKeyDB.sdf; Password = <mypassword>"
Cursor.Current = Cursors.WaitCursor
Try

RemoteAccess.Push("KeyHeader", RDAConnectingString, Data.SqlServerCe.RdaBatchOption.BatchingOn)

Catch RDAConnectionException As Exception
MessageBox.Show("Can not push Header Data: " & RDAConnectionException.ToString, "Loading Key Tracker")
Finally

RemoteAccess.Dispose()
End Try
Cursor.Current = Cursors.Default
End Sub

TABLE DEFINITION:
USE [MobileKeyDB]
GO
/****** Object: Table [dbo].[KeyHeader] Script Date: 07/11/2007 09:48:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KeyHeader](
[trans_id] [int] IDENTITY(1,1) NOT NULL,
[user_id] [int] NOT NULL,
[date_stamp] [datetime] NOT NULL,
[signature] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[status] [int] NOT NULL,
[id] [int] NOT NULL,
[date_stamp2] [datetime] NOT NULL,
CONSTRAINT [PK_KeyHeader] PRIMARY KEY CLUSTERED
(
[trans_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

Anyone have any insight on a solution? Thanks.

For synch scenarios, you should always avoid identity columns, for an elaboration, see http://blogs.msdn.com/synchronizer/archive/2007/06/28/stay-away-from-auto-increment-columns.aspx|||

Ok....then I will try using the unique identifier.

My problem is here that I am unsure of how to add the guid to my insert statement in my application.

I have a dataset created that has an Insert menthod for a my table.

How do I set the properties of this Insert statement to use a GUID in it's execution?

Thanks.

|||Modify your insert command to use NEWID(), see http://msdn2.microsoft.com/en-us/library/ms173249.aspx|||

Ok...thanks for your help.

I tried inserting the NEWID() method into my sql insert statement, however when I run my application in debug mode,

I get an Null Value Exception on that UniqueIdentifier field....what would the best way to identify where and why this is happening?

The error occurs when I try to close the form by clicking 'ok' after entering a record......

Error....

NoNullAllowedException was unhandled

Column 'ID' does not allow nulls.

Code Point where error is generated....

Private Sub KeysEditViewDialog_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

Me.KeysBindingSource.EndEdit()

End Sub

Some Dataset Code.....is the null error on the sql side or app side, I am not sure of this?

Me._adapter.InsertCommand = New System.Data.SqlServerCe.SqlCeCommand

Me._adapter.InsertCommand.Connection = Me.Connection

Me._adapter.InsertCommand.CommandText = "INSERT INTO Keys"&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)&" (key_number, key_desc, building, inv_qty,"& _

" avail_qty, id)"&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)&"VALUES (@.p1, @.p2, @.p3, @.p4, @.p5, NEWID())"

Me._adapter.InsertCommand.CommandType = System.Data.CommandType.Text

param = New System.Data.SqlServerCe.SqlCeParameter

param.ParameterName = "@.p1"

param.Size = 100

param.IsNullable = true

param.SourceColumn = "key_number"

Me._adapter.InsertCommand.Parameters.Add(param)

param = New System.Data.SqlServerCe.SqlCeParameter

param.ParameterName = "@.p2"

param.Size = 100

param.IsNullable = true

param.SourceColumn = "key_desc"

Me._adapter.InsertCommand.Parameters.Add(param)

param = New System.Data.SqlServerCe.SqlCeParameter

param.ParameterName = "@.p3"

param.Size = 100

param.IsNullable = true

param.SourceColumn = "building"

Me._adapter.InsertCommand.Parameters.Add(param)

param = New System.Data.SqlServerCe.SqlCeParameter

param.ParameterName = "@.p4"

param.DbType = System.Data.DbType.Int32

param.Size = 4

param.IsNullable = true

param.SourceColumn = "inv_qty"

Me._adapter.InsertCommand.Parameters.Add(param)

param = New System.Data.SqlServerCe.SqlCeParameter

param.ParameterName = "@.p5"

param.Size = 100

param.IsNullable = true

param.SourceColumn = "avail_qty"

Me._adapter.InsertCommand.Parameters.Add(param)

No comments:

Post a Comment