473,569 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

preventing duplicate row insertion from asp.net app

Data is stored in SQL Server 2000. One table is Person another Item.
Each row in the Person table may have associated with it several rows
in the Item table. The Item table has a field called 'type'. Business
rule: for certain values of this field, at most one row may exist (per
Person) in the Item table.

The DB is accessed from an ASP.NET app and more than one user may try
to insert an Item of the same type (and for the same Person) at the
same type. It would be very easy to ensure the above business rule
using a trigger (on the Item table) or a stored procedure that would
do inside something like this:
IF (NOT EXISTS (SELECT ... FROM Item)) INSERT INTO Item...

Please note that, because of internal coding standards, I cannot
modify the DB and I cannot access the database from my app through
direct SQL statements (e.g., like the one above). I can only access
the Item table through stored procedures that perform inside them
simple selects and inserts on the table.

Assuming the stored procedures (for SELECT and INSERT on the Item
table) are called inside the same method, is there a way to satisfy
the above mentioned business rule (ensure mutual exclusion) at the app
level? Would specifying the isolation level as serializable at the app
level work? Is there a better solution?

Thank you,
Alex
Nov 17 '05 #1
2 1862
Jerry,
Unortunately, I might not be able to modify the DB. (Besides, I do not
see how the SPECIFIED business rule would be enforced through a
primary key.)
I would still need to know if there is a way to enforce the business
rule at the app level.

Thanks,
Alex
"Jerry III" <je******@hotma il.com> wrote in message news:<#b******* ******@TK2MSFTN GP12.phx.gbl>.. .
The only good way to do this is using a primary key on the table. Trying to
enforce data consistency in the application layer is not a good idea and
will generally not work (because sooner or later someone will forget to do
so, intentionally or not).

Jerry

Nov 17 '05 #2
You can have a primary key spanning more than one column (which would be the
case of your specific rule).

And yes, there is a way, you will simply check if the value exists before
you try to insert it. There are multiple ways to do that and none will be
100% fool proof, if you forget to do it once (or someone else working with
the same data forgets to do it) or don't do it correctly (with regards to
multiple requests executing simultaneously) you will end up with data that
are "corrupted" based on your rules. You can do that checking with triggers,
stored procedures, or plain SQL, it's entirely up to you...

Jerry

<ab********@yah oo.com> wrote in message
news:34******** *************** ***@posting.goo gle.com...
Jerry,
Unortunately, I might not be able to modify the DB. (Besides, I do not
see how the SPECIFIED business rule would be enforced through a
primary key.)
I would still need to know if there is a way to enforce the business
rule at the app level.

Thanks,
Alex
"Jerry III" <je******@hotma il.com> wrote in message

news:<#b******* ******@TK2MSFTN GP12.phx.gbl>.. .
The only good way to do this is using a primary key on the table. Trying to enforce data consistency in the application layer is not a good idea and
will generally not work (because sooner or later someone will forget to do so, intentionally or not).

Jerry

Nov 17 '05 #3

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

Similar topics

3
6000
by: Raju V.K | last post by:
I am developing a PHP-mysql database. It is noted that when the browser window is refreshed the data is inserted again in the database. unfortunately there is no unique keys that I can use to verify the existance of the data, so as to prevent the multiple insertion. Is there any other way to prevent it otherthan introducing another field for...
18
27694
by: Elroyskimms | last post by:
I have a table using an identity column as its Primary Key and two columns (table reduced for simplicity) EmployeeNumber and ArrivalTime. CREATE TABLE ( IDENTITY (1, 1) NOT NULL , (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , NOT NULL , CONSTRAINT PRIMARY KEY CLUSTERED (
6
6387
by: nick4soup | last post by:
I have read the CGI FAQ 'How can I avoid users hitting "submit" twice' (on http://www.htmlhelp.org/faq/cgifaq.3.html#19 ) which essentially says you have to detect it at the server, using a hidden form field. That's fair enough. My server is therefore processing a response on the first request, so what kind of HTML response should I...
11
7495
by: Jean-Christian Imbeault | last post by:
I have a table with a primary field and a few other fields. What is the fastest way to do an insert into that table assuming that sometimes I might try to insert a record with a duplicate primary key and want that to fail? I know that if I try a plain insert this will work, but in the case where I am trying to insert a duplicate key, the...
6
6507
by: planetthoughtful | last post by:
Hi All, I have a C# ASP.NET page that submits back to itself to insert details from a form into a database table. When / if the user refreshes the page (and gets the standard warning that POST data will be resubmitted), the previously submitted record is sumbitted again, and a duplicate record is inserted into the table. In PHP I would...
8
2691
by: mindwarp | last post by:
Hi, When a user submits / posts data my php script Inserts data into my database. If they refresh the script or click back and click submit again I get duplicate record. Is there an easy solution to this? Or do I need to create a hidden field which contains some sort of
6
11877
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and clicks again, which created duplicate forcm submission and hence duplicate records. So I am trying to disable the button as soon as it is clicked,...
0
1581
by: =?Utf-8?B?SGF3aw==?= | last post by:
Hello, I have the need to verifiy a field in a gridview for a duplicate value against a database before the update takes place. I was thinking that the gridview1.rowupdating would be a good place to put code that can check for duplicate data before the update happens. Below is a sample of the code i was trying but did not work. ...
6
9007
by: reppisch | last post by:
Hi Ng, I have a multiset for keeping elements sorted in a container but key values may also be equal. Is there any guaranteed traversal order within the duplicate keys of a multimap? When inserting duplicate keys to the multiset i need output order to be in insert order.
7
17928
by: chowdary | last post by:
I am developing a PHP-mysql database. It is noted that when the browser window is refreshed the data is inserted again in the database. unfortunately there is no unique keys that I can use to verify the existance of the data, so as to prevent the multiple insertion.
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.