Click here to Skip to main content
15,918,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing an application of invoice printing.
Everything is working perfectly except that sometimes records are duplicated while saving the records.
it happens only for sometimes otherwise its working perfectly.
I am using vb.net as front end and sql server 2005 as back end.
The .net code is ok . this happens only 1 time within a week.

So pls. tell me the solution. i think its a problem of sql server.
I am not able to find it.

This happens only in the child table, due to the query is in the loop.

Only one record is inserted in the master table for the same table.
Posted
Updated 29-Dec-10 20:27pm
v2

That can only happen if insertion events is firing twice sometime.

Suppose you may have clicked button twice unfortunately.

Code snippets can only give us clarity. if you want you can.
 
Share this answer
 
Hi,

One thing is clear it is not a problem of sql server. Its saves what you are providing. Recheck your code and store procedure that saves your records. Recheck and redefine the keys and constraint of your table.
 
Share this answer
 
Actually, unlike everyone else here, I believe your issue is with the database, and here is why.

Any insert to a table, especially tables containing financial information, need to be protected and validated properly.

Inserts on tables like this should always go through a stored procedure so that the data can be validated as unique before it gets into the table as a duplicate. If the record that is trying to get inserted is found to be a potential duplicate, it should get written to a suspect record table which can then be manually reviewed so that if it is indeed valid, it can be transferred to the appropriate place.

Sandeep's answer is correct in that there is a refresh page issue in asp.net and that it could be a potential issue, but you should never, ever rely on the UI portion of an application to protect your data.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 29-Dec-10 16:37pm    
Good answer! 5+
Manfred Rudolf Bihy 29-Dec-10 16:43pm    
Also if duplicates aren't allowed, why does the database model not reflect that by defining an appropriate primary key? That would make duplicates impossible. Maybe the database model does not fit the applications purpose.
fjdiewornncalwe 29-Dec-10 16:52pm    
@Manfred: The part that scares me is that is is financial in nature... Boy do I hope this is a homework assignment and not a real-life scenario.
It does not sound an issue of SQL Server. Surely the insertion is being trigger more than once from frontend only. One such scenario I can tell you is of pressing 'Refresh' button of browser or pressing a F5 button.
In this case, the same events would be triggered and data can be duplicated. Check if that's the case. If so, have a look at this article to workaround it: Refresh Page Issue in ASP.Net[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900