如何解决死锁问题(deadlock)

cqn 2000-09-10 11:05:00
we are doing a project .
In one Save button , we must do much work.
(1) update a record for table A
(2) delete a record for table A
(3) add a new record to table A

All these action use the one transcation .
For example:
conn.BeginTran
UpdateRecord.
DeleteRecord
AddNewRecord.
conn.committran

But when we click the save button at same time useing two different computer, the system will occur deadlock.
The Database is SQL Server 7.0 and Develop Tool is VB6.0

If we get rid of the transcation , the system is ok.
and if we move the DeleteRecord and AddNew to out of the transcation, the system is ok too.
But we can't do like it , because the system must have transcation.
Please give you advice, Thank you very much.

...全文
697 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cqn 2000-09-11
  • 打赏
  • 举报
回复
I have create two view.
for example:
View1:
select * from tablea 'For add
View2:
select * from tableA 'For delete
Table a:
use the table a for update.

And then in the save button:
1) update tablea. ( use the table a)
2) Add a new record to table a ( use the view1)
3) delete a new record to table a (use the view2)
but the result is: the system will occur the deadlock still.
创业码农 2000-09-11
  • 打赏
  • 举报
回复
对不起,我只知道怎么解决这个问题。
如何建View我也不知道,不过这不是问题,参考"Sql Server Online Book"
我有个朋友就是用这个办法解决的。。。(Sybase+PB,C/S)

其实,这个问题在Orcale中解决的更好一些。
因为SQL Server和Sybase都是基于线程的(Process),
而Orcale是基于进程的(Thread),这样的结果我想你也是知道的。
因为WinDows9X或WinNT的Process之间的通信一直处理的不太好(When you pass Large Data)。

如果你不会用VIEW,可以加多张表临时表的方法的解决!

# step 1
private function CreateTmpTable(TableName as string)
dim cnn as adodb.connection
dim strSql as string
on error goto ErrOption
'now,you can replace your code in '...'
strsql="Create Table ..."+TableName
cnn.open gstrdbconnectstring
cnn.execute strsql
ErrOption:
'occur error on *create new template table*
if err.number=??? then
'add your error operation
end if
end function

# step 2
用存储过程建表!
在后台提交数据!

这两个方法都可以基本上解决问题(因为你把它交给SQL Server 完成了。)

上面只写了我现在的想法的一部分。
想法:把它们(DeadLock)交给后台(SQL Server)完成!!!因为Sql Server有自己的东西来处理它的。
而你不用在编自己的程序中处理了!!!

cqn 2000-09-11
  • 打赏
  • 举报
回复
There is no any wait in the save button .
and the system don't need the MTS. the system is typical C/S system. Only SQL Server 7.0 on the server and VB6 application on every computer.
About using the View. Please tell me how to update and delete a record in the view. I havn't used the view before.
创业码农 2000-09-10
  • 打赏
  • 举报
回复
1.做多少个VIEW(视图)可以基础上解决这个问题。

2.再者就是看你在Commit之前是否有Msgbox语句!!!系统和DBMS都将进入等待状态!!!
bluepeach 2000-09-10
  • 打赏
  • 举报
回复
please check the configuration of MTS between two computers!
bbslucky 2000-09-10
  • 打赏
  • 举报
回复
我也想知道
Putao 2000-09-10
  • 打赏
  • 举报
回复
DoEvents
Putao 2000-09-10
  • 打赏
  • 举报
回复
DoEvents

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧