DataBase - 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
Visual Studio .NET
(1)
SQL Server
(1)
Database
(1)
JavaScript
(1)
DataGrid
(1)
Sortable
(1)
Oddysey
(1)
Replica
(1)
  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
  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/
  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/
  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
  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
  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
help
04.2009, findet 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 Stammtisch für Datenbankentwickler ist ein auf http: / / www.dfpug.de / veran / regional / hamb / treffen.htm. Christof Wollenhaupt Regionalleiter Hamburg Microsoft Visual FoxPro MVP Access Discussions Visual Studio.NET (1) SQL Server (1) Windows Home Server (1) Softwareanforderungen (1) Datenbankentwickler (1) Erfahrungsaustausch (1) Hallo
Visual studio tools for version 9.0 DataBase Hi All, We are an ISV developing a custom great plains application for a client. We want to open a Great Plains window from Visual Studio .Net but we received an error that it was not a registered module. We would like to open the Vendor Maintenance window from a visual studio .Net application so they can use it from there but it says the module is not
VS Tools for GP9 - MDI Forms DataBase Is there a way to make a custom Visual Studio (.net) form act like a regular GP MDI child form? (Stay visible - not modal) I have according to it's master GP form. Any Suggestions? Thanks, Jim Harkins Great Plains Discussions Visual Studio (1) DexUIForm (1) MDIClient (1) HWndMDI (1) HWndNewParent (1) FindWindowEx (1) BlaBlaBla (1) InitializeComponent (1 VS, Tools, for, GP9, -, MDI, Forms description: Is there a way to make a custom Visual Studio (.net) form act like a regular GP MDI child form (Stay visible - not modal) I have
How to user Dataset created by Visual Studio 2008 DataBase Hello, I'm new in .Net world and there is so many info that I'm lost. DataSet is creted by Visual Studio 2008 to handle a FireBird database. Where can I find documentation about how to use the database and DataSet gets the relationship already done? Thanks, Access Tables DB Design Discussions Visual Studio 2008 (1) Database (1) Dataset (1) Castro (1) Tablesdbdesign (1) Efective (1) Theses (1) Hi Marco, You posted this in the Access Forum. It would be better in a .net forum. Bonnie http: / / www.dataplus-svc.com - - Message posted via AccessMonster.com http: / / www.accessmonster
I can't seem to find it. I have Office 2003 Professional installed I have Visual Studio 2003 .NET installed I have VSTO 2003 installed. From within Visual Studio .NET, I can see the MS Word and Excel Projects for VB and C#. Looking at my Visual Studio Tools CD, I see a relatively small setup.exe (<3MB) and just a readme.html