Click here to Skip to main content
15,890,946 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m facing a problem, I have API that sends a request with a list of email addresses, now what system does it check each email address from the database, if it exists then it ok we use userid else we create a new user.

The problem arises when we send multiple requests with the same list of email addresses then it throws an exception.because I have set a unique constraint on email column in DB.

What I have tried:

I think I have to create a singleton DB context and this context only create a user and return to the caller function.
Posted
Comments
Dave Kreskowiak 25-Nov-17 14:35pm    
Your question makes little sense.

Are you asking how to check to see if an email address is in your user database first before trying to add it?

If you attempt to add the email address now, you're getting an exception because the email address already exists? Then handle the exception and return the user back to the page to pick a new email address and include an error message in the page that says that address is already in use.
Code Atom 26-Nov-17 0:10am    
the use case is, first check if the user exists in DB or not, if not then create a new one else use existing one, now two threads parallelly try to create a user in their own thread scope and they try to commit their changes it basically throws an exception.
Dave Kreskowiak 26-Nov-17 0:21am    
And the exception is?
Code Atom 26-Nov-17 0:24am    
Transaction abort exception
Code Atom 26-Nov-17 0:26am    
Am I need to add row version in user table for concurrency? and I am using serializable isolation in the transaction.

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