Dynamic sequence generator

Hi,

I need to create unique senquence ids in my DB.

For this I ve created a form (say A)separately and store the current sequence no. count in it.

When ever I create a new document I fetch the current value of sequence no. from the form(A) , add one to it and store the new value in form A and also at the place where the id is required.

The problem is if multiple users are present , when they create a new document,they all access this same formA simultaneously to generate the sequence.

Hence this results in duplicate sequence no. generated causing a major flaw in the DB.

How can I generte unique ids in this case.

Subject: dynamic sequence generator

Hi,

one idea is that you don’t genarate the id when the document is created.

Wrote an agent, that genartes the id depending on date created or something.

e.g view with column ordered by create date, documents where the id is empty, generate id an save it in the document.

I think the probability that two users in the same second create a document is very small.

Subject: RE: dynamic sequence generator

there are hundreds of postings about the perils of trying to generate sequential document numbers. And it multiplies exponentially if you have replication. Try some of the better solutions.

Subject: Here is what I am using

Set view = db.GetView("Counter Form view")	Set doc = view.GetDocumentByKey("CounterForm")



If doc Is Nothing Then

	Set doc = db.CreateDocument

	doc.form = "CounterForm"

	NumToUse = 1

	doc.Counter = Cstr(NumToUse)

	Call doc.Save(True, False)

	NumToUse = 1

	Goto endfun

End If



For i = 1 To 100

	NumToUse = Cdbl(doc.Counter(0))

	doc.Counter = Cstr(NumToUse + 1)

	If doc.Save(False, False) Then

		Exit For

	End If

	Set doc = Nothing

Next

Subject: RE: Here is what I am using

Set view = db.GetView("Counter Form view")	Set doc = view.GetDocumentByKey("CounterForm")



If doc Is Nothing Then

	Set doc = db.CreateDocument

	doc.form = "CounterForm"

	NumToUse = 1

	doc.Counter = Cstr(NumToUse) ' why store the value as a string, when you need it a number to use it?

	Call doc.Save(True, False)

	NumToUse = 1 ' already had this value!

	Goto endfun

End If



For i = 1 To 100

	NumToUse = Cdbl(doc.Counter(0)) ' Object variable not set error, see below.

	doc.Counter = Cstr(NumToUse + 1)

	If doc.Save(False, False) Then

		Exit For

	End If

	Set doc = Nothing ' 2nd time thru your document will be Nothing! You have to Delete the object and fetch it again.

Next

Subject: RE: dynamic sequence generator

Assigning Unique/Sequential Document Identifiers