Visual Studio .NET
(1)
SQL Server
(1)
Database
(1)
JavaScript
(1)
DataGrid
(1)
Sortable
(1)
Oddysey
(1)
Replica
(1)

Custom Counter in Replica Database

Asked By lloyd sturge
21-Oct-09 10:25 AM
I have a custom counter in my application that has to be redesigned now that I have replicated the backend database for use with a laptop that will be taken on the road. The solution was to use direct synchronization. Which should work great.

The problem is the custom counter is a variation of the DMAX() solution will cause duplicate counter numbers to be generated in the replicas. The DMAX solution will probably not work either for my solution now because of the random generation of autonumbers now that the database is replicated. What alternatives do I have for implementing a custom counter in this scenario?

I am looking for advice or  alternative code that I can use/modify to work for my solution. This problem has to be fairly common for replica databases but I cannot seem to find much on it on the net. So I am asking the Access gurus out there what would be their solution? If anybody could point me in the right direction I'd appreciate it!
Thanks!

EggHeadCafe - Software Developer Portal of Choice
C# / JavaScript Client Side Sortable DataGrid
http://www.eggheadcafe.com/tutorials/aspnet/3a655dae-c735-498d-99cc-c7b21de74be4/c--javascript-client-si.aspx

The best answer for you may be based upon a better understanding of what

AccessTables.com replied to lloyd sturge
21-Oct-09 04:49 PM
The best answer for you may be based upon a better understanding of what the
custom counter was giving you.  For instance you mention that you have had
auto number also.  So it is not clear quite yet what the custom counter was
doing or why - relative to autonumber.

But that aside - one can implement an incrementer with code.  If the
underlying table's field property is that it must be a number - - then you
would need to put your multiple PCs into a specific number range so that they
can never overlap.  If the underlying field property is text then you could
have one PC incrementing A1,A2,A3 and your second PC incrementing B1,B2,B3.

Based on your feedback I can give more specific input.

Hope this helps

There are three general solutions to this problem:1.

David W. Fenton replied to lloyd sturge
21-Oct-09 07:58 PM
There are three general solutions to this problem:

1. allocate blocks of IDs for each replica, and select the next
available according to which replica the new record is being added
in. While SQL Server replication has a built-in capability for
implementing this, Jet replication provides no support for it, so
you will have to set it up yourself and implement it in your NEW
RECORD logic.

2. change the PK to be a two-column key, one of which indicates the
source replica, and the other of which is populated according to the
Max()+1 rule. This may or may not work. For instance, if your
code-generated PK is an invoice number, you would  have to redefine your
invoice number to include the source replica field in order for this
solution to be usable.

3. use random autonumbers for the real PK and then have one of the
replicas process the data to assign the code-generated numbers that
human beings use. This would not work in some applications, but in
an app where, say, multiple users generate invoices, but only one
person actually prints them and sends them out to customers, it
would work ust fine.

In any case, if you need a meaningful sequence, you have to either
replace your existing PK field with it, or add it as an additional
field to the random Autonumber PK.


I have never had to deal with this, as the only app where I was using
a "custom counter" was one in which it was just simpler to use a
MASTER/SLAVE setup, where only one replica at a time could add
records to the table with the code-generated PK. That app had only
two production replicas, one on a desktop and one on a laptop, and
the synchronization process automatically transfers MASTER status
appropriately (i.e., if the laptop synchs with the desktop, MASTER
status transfers to the laptop; when the laptop next synchs with the
desktop, MASTER status transfers back; there is also an override to
synch without changing MASTER status, but I am the only one who ever
uses it!).

That obviously does not help you in a situation where there is more
than one user.

The simplest solution is to allocate blocks of numbers to each
replica, seems to me. You have a choice of whether to do that by
populating a table and assigning the rangers, or of writing the
blocks into code, or of doing the much easier method, which is to
use the left-most column as the replica-specific number. How that
would work is something like this:

Replica 1       1,000,000 to 1,999,999
Replica 2       2,000,000 to 2,999,999
Replica 3       3,000,000 to 3,999,999
Replica 4       4,000,000 to 4,999,999

To do this, you would  assign the right 6 digits and then add N*1,000,000
to it, where N is the number you have allocated to the replica. So, if
the next available number is 9568, your sequence number would be
1009568 if you are generating it in Replica 1, and 2009568 for
Replica 2 and so forth.

This may be problematic for your accountants if they do not want,
say, invoice numbers to have gaps. But you should be able to
maintain each sequence within itself, so that should be an avoidable
(or, at least, explainable) problem. That is, there might be a gap
between 1009568 and 2000000, but there ishould be any gaps within the
sequence between 1,000,000 and 1,999,999.

--
David W. Fenton                  http://www.dfenton.com/
usenet at dfenton dot com    http://www.dfenton.com/DFA/

=?Utf-8?B?QWNjZXNzVGFibGVzLmNvbQ==?=Eh?

David W. Fenton replied to AccessTables.com
21-Oct-09 08:01 PM
=?Utf-8?B?QWNjZXNzVGFibGVzLmNvbQ==?=


Eh? There is no issue at all with using an Autonumber field (which
is little more than a long integer field with a special kind of
default value) and appending new records with a specific value for
it. That is, there is no prohibition at all on appending a specific
value to an Autonumber field so long as that value does not violate
the indexes on that field. In a PK field, that would require
uniqueness, so you cannot append with an existing value, but as long
as the value is not already in use, you can append any value you
like.

--
David W. Fenton                  http://www.dfenton.com/
usenet at dfenton dot com    http://www.dfenton.com/DFA/
I think I have a solution
lloyd sturge replied to David W. Fenton
23-Oct-09 09:09 AM
Thanks everyone for taking the time to answer my question. Some good ideas there for sure! But I think I have a good solution for my situation. My replication situation is simple, the ability to use a laptop version of the application on the road.

I have decided to seed the customer counter values, which I use for ID card numbering, to a new value that takes the existing max value on the laptop/local database only and seeds it by say 10,000. So the existing value of say 28000 would be seeded to 38000 after synchronizing. The custom counter table is not replicated. So the primary replica on the LAN is never updated. This counter is the primary counter. This gives me 10,000 potential records that can be added and never duplicated. The seed code checks to see if the seed is already applied by checking to see if the max seed value in the data table + the seed value is less then half the seed value. If so the seed is applied. If not code skips seeding. Now the next time the replicas are synchronized the new max seed value in the data is used to initialize the seed. This should in theory fill in the gap in the custom counter value over time and give me unique values since the get next counter number code checks for duplicates.

Anybody see any holes in this theory? Other then the number of potential counter values of the seed offset value but 10,000 records is very generous for this application. Make sense?

Thanks!




=?Utf-8?B?QWNjZXNzVGFibGVzLmNvbQ==?=Eh?
21-Oct-09

=?Utf-8?B?QWNjZXNzVGFibGVzLmNvbQ==?=


Eh? There is no issue at all with using an Autonumber field (which
is little more than a long integer field with a special kind of
default value) and appending new records with a specific value for
it. That is, there is no prohibition at all on appending a specific
value to an Autonumber field so long as that value does not violate
the indexes on that field. In a PK field, that would require
uniqueness, so you cannot append with an existing value, but as long
as the value is not already in use, you can append any value you
like.

--
David W. Fenton                  http://www.dfenton.com/
usenet at dfenton dot com    http://www.dfenton.com/DFA/

Previous Posts In This Thread:

EggHeadCafe - Software Developer Portal of Choice
SQL Server - Insert Record And Get New ID
http://www.eggheadcafe.com/tutorials/aspnet/4b5c0707-d70a-4e8a-ba7c-aa271ab7302a/sql-server--insert-recor.aspx
One more thing
lloyd sturge replied to lloyd sturge
23-Oct-09 09:12 AM
Sorry, I think I gave the impression that the autonumber field was involved, its not. Just a custom counter value of a string field actually. I am only interested in the "number" values of the string field.




I think I have a solution
23-Oct-09

Thanks everyone for taking the time to answer my question. Some good ideas there for sure! But I think I have a good solution for my situation. My replication situation is simple, the ability to use a laptop version of the application on the road.

I have decided to seed the customer counter values, which I use for ID card numbering, to a new value that takes the existing max value on the laptop/local database only and seeds it by say 10,000. So the existing value of say 28000 would be seeded to 38000 after synchronizing. The custom counter table is not replicated. So the primary replica on the LAN is never updated. This counter is the primary counter. This gives me 10,000 potential records that can be added and never duplicated. The seed code checks to see if the seed is already applied by checking to see if the max seed value in the data table + the seed value is less then half the seed value. If so the seed is applied. If not code skips seeding. Now the next time the replicas are synchronized the new max seed value in the data is used to initialize the seed. This should in theory fill in the gap in the custom counter value over time and give me unique values since the get next counter number code checks for duplicates.

Anybody see any holes in this theory? Other then the number of potential counter values of the seed offset value but 10,000 records is very generous for this application. Make sense?

Thanks!

Previous Posts In This Thread:

EggHeadCafe - Software Developer Portal of Choice
Installing Visual Studio .NET Beta 2: The Oddysey
http://www.eggheadcafe.com/tutorials/aspnet/3ed9b4c7-d35b-4992-a694-2d12d69bb89e/installing-visual-studio.aspx
And one more thing
lloyd sturge replied to lloyd sturge
23-Oct-09 09:22 AM
There will be more then one user. One user using the laptop on the road and a user in head office using the LAN version. So both replicas must have the ability to add/edit/delete records.




One more thing
23-Oct-09

Sorry, I think I gave the impression that the autonumber field was involved, its not. Just a custom counter value of a string field actually. I am only interested in the "number" values of the string field.

Previous Posts In This Thread:

EggHeadCafe - Software Developer Portal of Choice
.NET Exceptions: Promoting Good Design Patterns
http://www.eggheadcafe.com/tutorials/aspnet/36650df4-0d7b-4d8c-ad3f-634693a39445/net-exceptions-promotin.aspx
Post Question To EggHeadCafe
DataBase Might be outgrowing Access but daunted by SQL Server I am close to completing the consolidation of various small little company uses (5 staff) into an all encompasing Access database and I was planning on splitting the database when I was finished to allow simaltaneous use of it going to need to give staff access to this new database from remote locations (outside of our office network). Two staff to link tables from remote locations (ftp path of the database on our Network Storage Device at the office) and needless downloading, installing and trying to get my head around Microsoft SQL Server 2008 Express and how it might help me out. It came across a very encouraging article on keeping your Access database as your front end application and linking to SQL Server
DataBase Hamburger Stammtisch für Datenbankentwickler, Do. 09.04.2009 Hallo zusammen wieder der Hamburger Stammtisch für Microsoft Datenbankentwickler statt. Wer also SQL Server, Visual Studio.NET, Access, Visual FoxPro, oder andere Microsoftprodukte verwendet, ist herzlich eingeladen. Der Hamburger veran / regional / hamb / treffen.htm. Christof Wollenhaupt Regionalleiter Hamburg Microsoft Visual FoxPro MVP Hallo, Auch einen Vortrag gibt es wieder: WHS MVP Olaf Engelke wird uns den Microsoft Windows Home Server vorstellen. Er wird uns zeigen, worum es sich beim WHS wieder der Hamburger Stammtisch für Microsoft Datenbankentwickler statt. Wer also SQL Server, Visu
DataBase Usin VB in Sql Server Hi, I Upsized an Access database to SQL Server 2008 Express, so I will be able to create a .NET application so the public will be able to view the get error messages that those functions are not defined in SQL Server. What can I do? Can I port the VB code over to SQL Server so it will recognize those functions? Thanks!! SQL Server
DataBase Hamburger Stammtisch für Microsoft Datenbankentwickler, 11.03.2010 Hallo zusammen informelles Zusammentreffen, das dem Erfahrungsaustausch und der Kontaktpflege dient. Wer SQL Server, Visual Studio.NET, Access, Visual FoxPro, oder andere Microsoftprodukte verwendet, ist herzlich eingeladen. WICHTIG: Wir veran / regional / hamb / treffen.htm Christof Wollenhaupt Regionalleiter Hamburg Microsoft Visual FoxPro MVP keywords: Hamburger, Stammtisch, für, Microsoft, Datenbankentwickler, , 11.03
DataBase Access 2007 bug with SQL Server Back End I am posting this at the suggestion of response to another of my posts. Access 2007 SP2 with SQL Server 2005 back end. Datasheet form bound to an updatable view the way the Access retrieves a newly inserted record from SQL Server. If the view or table that a form is bound to contains an autonumber (identity) field, Access will query SQL Server for the last inserted value and then query SQL Server for the new record using PkField = IdentityValue, in order
DataBase Access 2007 and Visual Studio 2008 Hello I've been asking to write a small departamental application. My App will be on a remote file server and users will operate using links to the specific folder web servers nor will install them or other kind of server, like SQL Server (so, web app are out!). To build a pure Access application it seems that i'm stucked with VBA as visual studio 2008 does not support Access in new VSTO tools for Office System. Is this right?! Does Visual Studio 2008 lacks the ability to provide a way of
DataBase ODBC Connection to SQL Server Compact Dear All, I wrote VBA code in Access 2003 for a PDA. . .and therefore it is required to access SQL Server Compact 3.5 Following that I came up with a Close End If pConn.Open 'Delete All Records from Mobile Database pConn.Execute "DELETE * FROM StockItems" 'pRs.Open pRs.Close pConn message in question. The next stage would be to write Visual Basic code in Visual Studio 2005 that it would run on the PDA (using the data copied from Access on the SQL Server Compact database) for collecting data and then transfer the
DataBase Datenbankentwickler Stammtisch Hamburg am Do. 08.01.2009 Hallo zusammen der letzten Jahre hat sich herausgestellt, dass die Teilnehmer des Visual FoxPro Stammtisches in Hamburg unterschiedliche Entwicklungsumgebungen nutzen. Dies wurde zuletzt dadurch gefördert, dass Microsoft die Fortentwicklung von Visual FoxPro eingestellt hat. Daher möchten wir die Einladung zum Stammtisch auf alle Datenbankentwickler ausdehnen, die Microsoftprodukte einsetzen. Wer also SQL Server, Visual Studio.NET, Access, Visual FoxPro, oder andere Microsoftprodukte verwendet, ist herzlich eingeladen. Der Hamburger unter allen Teilnehmern eine von Microsoft gesponserte Version von Microsoft Visual Studio Team System 2008 Team Suite mit MSDN Premium verlost