Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i have a c# program that 2 user in network can use it (database is in my computer)
in sql server i follow this way --->right click on database --->properties--->option-- restict access-->
and choice : Single_User . it means one user in a time can access to data base .
now :
1- what happend if another user try to access to this database in same time ?
2- in this case i dont want my program show eror or any thing else ! i want user no2 automaticaly wait till user no1 close then databas and make it free !
how can i do it in c sharp ?!
Posted
Comments
Tomas Takac 1-Feb-15 10:28am    
Why would you do such thing? Single user mode is for maintenance, not for normal operations.
itman2 1-Feb-15 10:56am    
it is a sales program . for example we have 3pen for sale .
user1 want to sale 2 pen and in same time user2 want to sale 2 pen too .
what is you solution for this case ?
PIEBALDconsult 1-Feb-15 10:38am    
After all the work that thousands of very smart people put in to make concurrent access feasible you're goint to try to undo it?

1 solution

Look for optimistic concurrency. I'm sure there is support for this scenario in majority of data access technologies out there, e.g.:

Generally you compare the data that you have loaded in your app to the data in your database just before the update. In your example of buying pens this would go something like this:
SQL
update stock_table
set amount = @new_amount
where id = @pen_id 
and amount = @old_amount

if @@ROWCOUNT = 0 RAISERROR(...)

This way you can be sure that nobody else update the row in the meantime. Or you can use a dedicated version column. But you definitely need to do some reading first.
 
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