MIDAS中事务并发的问题(200分)

  • 主题发起人 主题发起人 tonglifeng
  • 开始时间 开始时间
T

tonglifeng

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个APP SERVER,工程其中有一个主FORM(上面有TDATABASE构件)
若干个TRemoteDatamodule(里面的QUERY等的DATABASE属性指向FORM中的DATABASE),TRemoteDatamodule为miMultiInstance,有个过程如SAVE(在一个事务中存取多个表SQLSERVER6.5)供客户端调用,应用中发现,当出现事务并发时,报 a user transaction already in progress错误,请问,我的问题出在哪里?代码结构如下:
database1.starttransaction
try
provider1.apply...
provider2.apply...
database1.commit
except
database1.rollback
end;
 
为什么不把TDATABASE构件放在TRemoteDatamodule中。
 
to g622:
有关系吗?
 
TProvider creates a transaction for the update operation
---------------------
and then
calls the ApplyUpdates method of its Resolver component.
去掉你写的Database.StartTransaction
 
to crane: 只是奇怪。
agree xwolf
 
to xWolf:
这怎么行,人家是要把几个provider当作同一事务!
 
据说把DATABASE放在REMOTEDATAMODULE中,并放入一个SESSION构件,设置其
AUTOSESSIONNAME为TRUE,可以解决,但若把DATABASE。KEEPCONNECT:=TRUE
会不会浪费SQLSERVER的连接数量,从而影响其性能?
 
我还有个问题请教各位,我有个程序(MIDAS客户端DELPHI5)如果把某个窗体打开
在编译,则退出DELPHI时报地址错,若不打开则正常,若打开——编译——CLOSE这个UNIT——退出则也正常。不知是什么问题
 
the key is where did u put the implementation of "save" method under
the option miMultiInstance.
i guess that u published the "save" method thru remotedatamodule to
client. u should code the method like following:
on remotedatamodule:
procedure Save(...);
begin
//call the implementation code on another unit (here is Form1)
do
Save(...);
end;

on Form1
proceduredo
Save(...)
begin
database1.starttransaction
try
provider1.apply...
provider2.apply...
database1.commit;
except
database1.rollback;
end;
end;
 
通过DCOM调用Application Server时,Tthreading Modal是对TRemoteDatamodule而言,Main Form应该在默认Thread中运行。当多台客户机同时运行同一个Server时,就有对应个数的TRemoteDatamodule对象被启动。
DATABASE放在TRemoteDatamodule中并不影响同一事务处理,SESSION构件是需要的。
 
在这种情况下,Inprise不推荐自己使用事务,应该用ApplyUpdates自动处理事务.
实际上,数据库操纵只要2种:
1.单据录入.不论单表还是主从表,用ApplyUpdates都没问题.
2.转帐类.不要用Delphi做,用存储过程做.
 
to liuz:
请问:DOSAVE放在哪里有什么不同?
 
App server is a multi-thread program. each remotedatamodule is in its
own thread. u put tdatabase in main form, every rmd invoke it from own
thread. this condition like that serval threads invoke the same
resource outside.
for instance:
user A begin
to save using your original routine. now TDatabase is in
a transaction. because of multi-thread, during A saving the data,
another user B can begin
to save also, then
your routine requests
TDatabase in main form to begin
another transaction. so the error
"a user transaction already in progress" happened.
how to solve:
one way is like i told u last time to modify save routine, make multi-
thread into single thread when saving data.
another way is that put TDatabase component in remotedatamodule and
set HandleShared = True. let each thread own his database session.
this way is recommended strongly.
 
TO LIUZ:
这么做过吗?
 
提供以下几點相關意見,供參考:
1 N_Tier開發中要求把數据連接控件放在server端,Tdatabase一般要放在RemoteDatamodule中,設HandleShared = True.
2 applyupdate() 執行時自動啟動一個事務,在這個事務中可以保証數据的一致性.
3 在前端与后端協同完成一個事務:用一個variant型變量傳遞要保存的多個數据集(delta)到后端再啟動事務.
...



 
台湾的李维教过一招,但现在不记得了,回家看看书再来告诉你.
 
of course. i have been engaged in developping Midas application for
about tow years.do
u try it.do
es it work?
welcome further question.
 
Database不支持嵌套事务,因此将Database放在Form中就使多个
RemoteDatamodule共用了同一个Database,当再次启动事务时便会
出错。
将Database放在RemoteDatamodule中,这样每个RemoteDatamodule
都使用的是独立的Database,就可避免错误出现。
 
使用session组件,并设置其AutoSessionName属性为True,否则所有的用户都使用
同一个默认的session,肯定会有影响。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
708
DelphiTeacher的专栏
D
后退
顶部