开发者

Unique constraint - these columns currently doesn't have unique values..?

开发者 https://www.devze.com 2023-03-03 14:46 出处:网络
Unique constraint - these columns currently doesn\'t have unique values..?? i have created Unique Con开发者_开发知识库straint with 3 columns ;

Unique constraint - these columns currently doesn't have unique values..??

i have created Unique Con开发者_开发知识库straint with 3 columns ;

my code works perfectly but once - two users @ same time entered same data and somehow it saved in DB; after that incident

This UniqueConstraint gives me error - These columns currently doesn't have unique values

How can i check if user enters this kind of entry or how can i restrict the ENTRY ???


Can you give more details about the constraints and how you are enforcing them?

(I thought) Any modern DBMS should be able to handle concurrency/multiple users at the same time without constraint problems. My guess is that you are using ADO.NET DataSet/DataTable and adding constraints yourself.

If that's the case, I think the easiest/best thing to do is to add the constraint in the database as well. If two users update/save at the same time, the database will handle it correctly; one will successfully save data, the other will receive an error. You can handle that error in the application gracefully.


I guess you're using SQL Server, in which case, if the constraints have been defined such that the constraint is checked upon insert. According to the SQL Server documentation, what you describe cannot happen:

The Database Engine automatically creates a UNIQUE index to enforce the uniqueness requirement of the UNIQUE constraint. Therefore, if an attempt to insert a duplicate row is made, the Database Engine returns an error message that states the UNIQUE constraint has been violated and does not add the row to the table.

Even if the inserts happen (almost) simultaneously, the requests will be queued in the database, so that one of the requests will fail if it detects the constraint would be violated.

As Rob P says, it looks as though you are creating the constraints outside of the DB layer.

0

精彩评论

暂无评论...
验证码 换一张
取 消