473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

where to put this code?

I have a C# class that generates a string based on 2
integers. One integer is equal to int.MinValue and the
other is equal to int.MaxValue. Each time my class
generates a new string from those 2 numbers, one of the
integers is incremented.

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.

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.

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?

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.
Nov 19 '05 #1
2 1174
"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 you
can use a PK? Or this newly generate PK should be checked as soon as
possible 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 believe
typically 20+ minutes of inactivity. There maybe other situations where
application end is fired.

But generally speaking, you don't want to use Application_End for
process that MUST occur... because application_end has been shown to be
unreliable 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... such
as checking the PK to make sure it's a valid PK before returning back to
the user. It's probably not a good idea just to rely on an XML file or
in memory store... as they could get out of sync with the server or data
could 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/
Nov 19 '05 #2
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/
.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rachel Weeden | last post by:
I'm working on an ASP Web application, and am having syntax issues in a WHERE statement I'm trying to write that uses the CInt Function on a field. Basically, I want to select records using...
2
by: BoB Teijema | last post by:
Hi all, One of our companies is having problems with a query on a linked server. They have two servers, serverA and serverB. On serverA they have set up a linked server to serverB. Query:...
4
by: Barry Edmund Wright | last post by:
I would really appreciate your assistance. I am using Access 2000 to create a form that Lists Names and Addresses based on a number of selection criteria one of which is a combo box cboPCZip. All...
16
by: Dixie | last post by:
I have a problem using Dev Ashish's excellent module to concatenate the results of a field from several records into one record. I am using the code to concatenate certain awards onto a...
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
10
by: Ray Stevens | last post by:
I am attempting to test a VeriSign account and the setup instructions stated that the certs file needed to go into the Windows\System32 folder. I am getting an error from the code-behind assebly...
7
by: Britney | last post by:
Original code: this.oleDbSelectCommand1.CommandText = "SELECT TOP 100 user_id, password, nick_name, sex, age, has_picture, city, state, " + "country FROM dbo.users WHERE (has_picture = ?) AND (sex...
0
NeoPa
by: NeoPa | last post by:
Background Whenever code is used there must be a way to differentiate the actual code (which should be interpreted directly) with literal strings which should be interpreted as data. Numbers don't...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
0
NeoPa
by: NeoPa | last post by:
Intention : To prepare a WHERE clause for multiple field selection, but to ignore any fields where the selection criteria are not set. ONLY WORKS WITH TEXT FIELD SELECTIONS. Scenario : You have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.