I agree, it's not safe, I think I knew that when I posted,
just probing for a new perspective on my problem.
Technically, it could work, but I don't like the idea of
relying on a file and the events fired on the web
application itself, too disparate to be managed appropriately.
What I have is a 32-bit hexidecimal value that I use for a
primary key, I call it an OID. It is binary but can be
read as a 16-character string, prefixed by a "0x" (i.e.
"0x000045F4BD20A3C2"). In C# this is a byte array.
I use two 32-bit integers to generate these OIDs and use
them as my primary keys. This is useful because every
single record in my database is globally unique. Since it
would take a rediculously long time to run out of OIDs you
can even make your records globally unique across your
databases, should you require it.
Anyhow, I don't want to generate them in the database for 2
reasons.
1. Not portable. I have a T-SQL version already written
but now I'm using Firebird and I don't want to re-write the
logic in Firebird's query language. Even if I do, what if
I want to use this in another database someday? Obviously
a bad design choice.
2. Rount-Tripping & Performance. I would have to run
round-trip to a table on every single record added to the
database to get my OIDs. On bulk or large inserts, this
could be a real drag.
So, since I have already taken the time to re-write the
T-SQL procedure in C#, and it works great (using a file or
database table), I'd like to find the most
efficient/safe/portable way to implement it.
I gave you the short, now there's the long of it!
Thanks,
-v
-----Original Message-----
"V. Jenks" <an*******@discussions.microsoft.com> wrote in
news:11****************************@phx.gbl:
What I need is a way to safely store the current string and
the 2 integers in a way that will guarantee I do not lose
the values, it is important that each time I generate the
string, it is unique, as it is used as a primary key in my
database tables.
Not a very safe way of generating PKs... Isn't there
anything else youcan use a PK? Or this newly generate PK should be checked
as soon aspossible to ensure it's uniquness.
If I were to load the values from say, an XML file when the
program loads in Application_Start in the Global.asax
code-behind, could I safely keep them in memory and are
they guaranteed to remain in state while the application is
running? I was thinking I would re-write the values back
into the XML file in the Application_End event handler.
No, if the application crashes, bye bye values!
BUT...when exactly is Application_Start fired and when
exactly is Application_End fired? What constitutes a web
application starting and ending? Does it end when there
are no more active sessions in the app?
Applicatin Start is fired when the application is first
loaded.
Application End is fired when the application is shut down
- I believetypically 20+ minutes of inactivity. There maybe other
situations whereapplication end is fired.
But generally speaking, you don't want to use
Application_End forprocess that MUST occur... because application_end has
been shown to beunreliable from time to time.
Could I safely pull this off w/o any concurrency problems
when writing/reading to the XML files to get my values?
I would store these values in a database table but I don't
want to make a new connection and round-trip to the
database every time I need a value to insert as a primary
key, this would murder my app's performance.
Perhaps you should look at generating the key in the database?
Or add some error handling logic in your PK generation
routines... suchas checking the PK to make sure it's a valid PK before
returning back tothe user. It's probably not a good idea just to rely on an
XML file orin memory store... as they could get out of sync with the
server or datacould have been lost on a crash.
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
.