间歇性的数据库连接 [英] intermittent database connection
问题描述
hi
i有一个ac#程序,网络中的2个用户可以使用它(数据库在我的电脑中)
在sql server中我按照这种方式--->右键单击数据库--->属性--->选项 - restict访问 - >
和选择:Single_User。这意味着一个用户一次可以访问数据库。
现在:
1-如果其他用户同时尝试访问此数据库会发生什么?
2-在这种情况下,我不希望我的程序显示错误或任何其他东西!我希望用户no2自动等到用户no1关闭然后数据库,并使其免费!
我怎么能用c sharp做这个?!
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 ?!
推荐答案
寻找乐观并发。我确信大多数数据访问技术都支持这种情况,例如:
- 数据适配器 [ ^ ]
- LINQ to SQL [ ^ ]
- 实体框架 [ ^ ]
- NHibernate [ ^ ]
Look for optimistic concurrency. I'm sure there is support for this scenario in majority of data access technologies out there, e.g.:
- Data adapters[^]
- LINQ to SQL[^]
- Entity framework[^]
- NHibernate[^]
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.
这篇关于间歇性的数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!