﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Sql Replication Guid Field</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 13:39:48 GMT</lastBuildDate><ttl>20</ttl><item><title>Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1072.aspx</link><description>I am planning on using replication between branch offices and the corporate office. Using replication requires a guid field in each table which is fine, I am even considering using it as my primary keys as each office's data will be consolidated into one db.&lt;/P&gt;&lt;P&gt;The real problem I am having is the column with the Guid type is set to have a default value of newsequentialid() which from what&amp;nbsp;I have read eliminates alot of the index issues with using guids by making the id sequential. How do&amp;nbsp;I configure the BO to&amp;nbsp;pass default to allow sql to generate newid. I know I can generate a guid on the .net side but it does not seem to be sequential.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;P</description><pubDate>Thu, 04 May 2006 13:32:42 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1087.aspx</link><description>No, stuff like that isn't obvious... it's just that I've seen that error message enough to know what it is ;)</description><pubDate>Thu, 04 May 2006 13:32:42 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1086.aspx</link><description>You were correct I had accidently left the renamed pk as identity. Sometimes you look at something too much and miss the obvious,</description><pubDate>Thu, 04 May 2006 13:31:24 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1085.aspx</link><description>What you have is correct.  The problem is that one of the columns in your table has an IDENTITY specification on it.  Check the columns on your table and make sure that you don't have IDENTITY turned on on any of them.&lt;br&gt;
&lt;br&gt;
But yes, you are correct in that when you want to use a GUID pk, you're better off creating your own guids on the client side than trying to retrieve the value from the server.</description><pubDate>Thu, 04 May 2006 13:12:52 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1084.aspx</link><description>Thanks Ben,&lt;/P&gt;&lt;P&gt;I was kinda hopeful to use guid's as a primary key the more I thought about it. My current PK in an int type that is prefixed by a 3 digit office code. While this approach works it is not nessasarily ideal for a number of reasons. &lt;/P&gt;&lt;P&gt;However googling around I found some examples to "modifiy" a guid to make it sequential by datetime.&amp;nbsp;I have a guid field as my primary key no default value set and rowguid set to no,&amp;nbsp;auto increment turned off on the&amp;nbsp;BO. I am&amp;nbsp;setting the pk_id&amp;nbsp;in the setdefaultvalues method of the bo. I get the following error.&amp;nbsp;&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; SalesmenBO_SetDefaultValues()&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.sm_pk_id = NewSeqGuid()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;Cannot insert explicit value for identity column in table 'salesmen' when IDENTITY_INSERT is set to OFF.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the correct way to provide my own pk?&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;Public&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Shared&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Function&lt;/FONT&gt;&lt;FONT size=2&gt; NewSeqGuid() &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; Guid&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; laGuid() &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Byte&lt;/FONT&gt;&lt;FONT size=2&gt; = System.Guid.NewGuid.ToByteArray&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; ldBaseDate &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime(1900, 1, 1)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; ldNow &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime = DateTime.Now&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' Get the days and milliseconds which will be used to build the byte string &lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; strucdays &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; TimeSpan = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt; TimeSpan((ldNow.Ticks - ldBaseDate.Ticks))&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; strucmsecs &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; TimeSpan = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt; TimeSpan((ldNow.Ticks _&lt;/P&gt;&lt;P&gt;- (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime(ldNow.Year, ldNow.Month, ldNow.Day).Ticks)))&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' Convert to a byte array &lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' Note that SQL Server is accurate to 1/300th of a millisecond so we divide by 3.333333 &lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; laDays() &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Byte&lt;/FONT&gt;&lt;FONT size=2&gt; = BitConverter.GetBytes(strucdays.Days)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; laSecs() &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Byte&lt;/FONT&gt;&lt;FONT size=2&gt; = BitConverter.GetBytes(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;CType&lt;/FONT&gt;&lt;FONT size=2&gt;((strucmsecs.TotalMilliseconds / 3.333333), &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Long&lt;/FONT&gt;&lt;FONT size=2&gt;))&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' Reverse the bytes to match SQL Servers ordering &lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;Array.Reverse(laDays)&lt;/P&gt;&lt;P&gt;Array.Reverse(laSecs)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' Copy the bytes into the guid &lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;Array.Copy(laDays, (laDays.Length - 2), laGuid, (laGuid.Length - 6), 2)&lt;/P&gt;&lt;P&gt;Array.Copy(laSecs, (laSecs.Length - 4), laGuid, (laGuid.Length - 4), 4)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Return&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt; System.Guid(laGuid)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Function&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Thu, 04 May 2006 11:51:37 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1082.aspx</link><description>Well, Paul, you're right, and there is no way to retrieve the last created GUID through either the NewID or NewSequencialID methods.  We have a pending feature request for the ability to retrieve columns other than the PK from the server.  Essentially, you specify the column(s) you want to retrieve from the server after an insert and the BO retrieves them... Looks like you'll have to wait until that feature is implemented to do what you want to do.  Then, you can make your Primary Key an IDENTITY integer, and let replication services have it's GUID column that's assigned either by NewID or NewSequencialID and gets retrieved after you insert a new record.  &lt;br&gt;
&lt;br&gt;
I'll try to get that feature request bumped up and let you know when it's implemented :ermm:</description><pubDate>Thu, 04 May 2006 10:11:29 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1081.aspx</link><description>&lt;IMG src="http://forum.strataframe.net/Uploads/Images/01e6d63b-5631-48e2-a399-f1c0.JPG"&gt;&lt;/P&gt;&lt;P&gt;Here is&amp;nbsp;a shot from Sql</description><pubDate>Thu, 04 May 2006 09:52:22 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1080.aspx</link><description>[quote][b]Ben Chase (05/04/2006)[/b][hr]What you'll need to do is leave the business object's PrimaryKeyIsAutoIncremented property to True. This will inform the business object that the server needs to assign the GUID value. Then, just like you said, put the NewSequentialID() function as the default value for a column. When your business object saves the record, it will insert a NULL value for the PK and retrieve the assigned value from the server, just as if it was an IDENTITY column.[/quote]&lt;/P&gt;&lt;P&gt;Ben this doesn't work i receive the following error.&lt;/P&gt;&lt;P&gt;Cannot create INSERT command because PrimaryKeyIsAutoIncremented = True and the PrimaryKeyField is not a valid auto-increment data type.</description><pubDate>Thu, 04 May 2006 09:42:29 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1077.aspx</link><description>Ok,&lt;/P&gt;&lt;P&gt;I guess that makes my decision on using them for PK's. :)</description><pubDate>Thu, 04 May 2006 08:51:05 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1076.aspx</link><description>No, not really.  For the business object to automatically retrieve the value without you needing to requery after saving the new records, it will need to be the PK.</description><pubDate>Thu, 04 May 2006 08:41:17 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1075.aspx</link><description>Ben currently I am not using it as a Pk field. Sql added the Field when&amp;nbsp;I set up replication. I am considering using it as a Pk&amp;nbsp;however.&amp;nbsp;Is there a way to do this without it being a PK?&amp;nbsp;</description><pubDate>Thu, 04 May 2006 08:37:47 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: Sql Replication Guid Field</title><link>http://forum.strataframe.net/FindPost1074.aspx</link><description>What you'll need to do is leave the business object's PrimaryKeyIsAutoIncremented property to True.  This will inform the business object that the server needs to assign the GUID value.  Then, just like you said, put the NewSequentialID() function as the default value for a column.  When your business object saves the record, it will insert a NULL value for the PK and retrieve the assigned value from the server, just as if it was an IDENTITY column.</description><pubDate>Thu, 04 May 2006 08:29:26 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item></channel></rss>