StrataFrame Forum

Primary Key GUID for Replication

http://forum.strataframe.net/Topic3583.aspx

By Paul Chase - 10/13/2006

A few months ago I was playing around with a few different scenarios for upgrading a fox 2.6 payroll app to .Net/Sql.

Basically we have a number of branch office's that will be running the application using a local data source. It is important that this data source be local as we cannot afford the possibility of downtime due to internet connectivity as well as possible latency issues etc.

The idea was to design the data so that it would replicate to a centralized DB as well as replicate back to the individual offices using a PK guid field and having an officeid field to indicate the office that generated the data.

So branch A would replicate to main server and then back to branch B and vice versa thus all branches would have a "full" set of data that would then be filtered by the officeid field in the data so they would only be "looking" at their data. 

The problem was with trying to update a record with the guid PK. It would throw an exception and bomb out. I remember talking with Ben about this and do not remember what the outcome was. Due to another project I had to put this on hold and am just starting to get back into thinking about design issues.  I was wondering if this has been resolved since then or if you guys have any other suggestions on how to handle this type of scenario.

Thanks

PAul 

By StrataFrame Team - 10/13/2006

Yes, you can do the Guid PKs now.  You can do them one of two ways... tell the business object that the PrimaryKeyIsAutoIncremented = False and set the primary key within the SetDefaultValues() event handler to Guid.NewGuid() or you can set the PrimaryKeyIsAutoIncremented = True and use stored procedures with an output parameter as the new GUID that was assigned.  Like this:

CREATE PROCEDURE MyTableInsert
   @pk UniqueIdentifier OUTPUT,
   @field1 VarChar(50)
AS
   SELECT @pk = NEWID()
   INSERT INTO MyTable (pk, field1) VALUES (@pk, @field1)

You have to manually assign the GUID since if you just put NEWID() in as the default value of the column, there's no way to get it back out.

As for the ROWGUID field that is used for replication, if it is also the primary key, then you're done, but if it's a separate column, then you'll want to set the field in the SetDefaultValues() event handler to DbNull.Value so that the server can assign it; you won't have to worry about retrieving since it's only used for replication.

By Paul Chase - 10/16/2006

Thanks for the answer Ben. I will try to test it out sometime this week and you will be the first to know if I have any issues. Smile

Paul

By StrataFrame Team - 10/16/2006

Just keep me posted.  Thanks Smile