ASP + COM(MTS)系统中的问题 (96分)

  • 主题发起人 主题发起人 freedomRen
  • 开始时间 开始时间
F

freedomRen

Unregistered / Unconfirmed
GUEST, unregistred user!
在做一个分布式系统:使用ASP + COM+方式
COM+是使用ASP对象(Active Server Object)和MTS对象(Transactional Object)方式,
通过ASP对象提供接口给.asp文件,在ASP对象接口中创建MTS对象,调用MTS对象接口方法,
在MTS对象中处理事务逻辑。
我在测试的时候,如执行客户端浏览器调用client.asp,
这个client.asp 通过Server.CreateObject(ProgID)创建远程ASP对象,
再调用远程ASP对象提供的接口方法,第一次可以调用成功,再次调用的时候出现错误:
“DAX错误,对象打开时不允许操作” ,过1,2分钟后再执行(或刷新)又可以
了,不知道是哪里的问题?

我在看李维的那本《ADO/COM+/MTS》,请各位指点一下此类构架的经验 :)
以及注意的一些问题,谢谢!
 
若说是资源释放问题,我实在找不出,在MTS对象中只有一个全局变量
var
ConnDb:TADOConnection;
是在MTS对象initialize的时候构造的,用来做所有数据集构件的连接数据库用途
而这些数据集构件ADOQuery均是局部变量,动态创建的,有freeAndNil(),MTS接口
每个处理事务逻辑的方法使用后都setComplete。。。原因我找不到 :(
 
分数太少?
给点建议意见嘛
 
代码如下:
MTS线程模式是:Apartment
交易模式是:Requires a Transaction
============================================
实现代码
=============================================
unit uMTSObject;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ActiveX, Mtsobj, Mtx, ComObj, PMTSObject_TLB, StdVcl,Global,DB,ADODB,
Sysutils;
type
TMTSObject = class(TMtsAutoObject, IMTSObject)
protected
function getConnectionString: WideString;
safecall;
function getTheCarInfo(const theCar: WideString): WideString;
safecall;
function CheckRequest(const value: WideString): WideString;
safecall;
function ExecutePay(const EndDate, TheCar: WideString): WideString;
safecall;
public
procedure Initialize;
override;
procedure ConnectionDb;
{ Protected declarations }
end;

var
ConnDB:TADOConnection=nil;
implementation
uses ComServ,uDataModule;
//取得数据库连接字符串
function TMTSObject.getConnectionString: WideString;
begin
if Assigned(ConnDB) then
result:=ConnDB.ConnectionString;
end;

//取得车辆信息,theCar:车牌号
function TMTSObject.getTheCarInfo(const theCar: WideString): WideString;
var
Query:TADOQuery;
begin
result:='';
Query:=nil;
try
Query:=TADOQuery.create(nil);
Query.Connection:=ConnDB;
with Querydo
begin
close;
Sql.Clear;
SQL.Text:='SELECT b.* ,name,sys_yl,sys_jj'+
' FROM owner a ,vehicle b WHERE car_num ='+''''+theCar+''''+
' AND a.id=b.id'+
' AND b.flag_yd <>''2'''+
' AND b.flag_yd <>''4''';
prepared;
Open;
if not eof then
result:=format(theCarInfoContent,[fieldbyName('car_num').asString,
fieldbyName('id').asString,
fieldbyName('name').asString,
fieldbyName('date_rh').asString,
fieldbyName('date_cc').asString,
fieldbyName('model').asString,
fieldbyName('Engine_Num').asString,
fieldbyName('bone_Num').asString,
fieldbyName('car_type').asString,
fieldbyName('load_hd').asString,
fieldbyName('seat_f').asString,
fieldbyName('seat_b').asString,
fieldbyName('flag_kh').asString,
fieldbyName('load_jz').asString,
fieldbyName('seat_jz').asString,
fieldbyName('flag_yy').asString,
fieldbyName('flag_yd').asString,
fieldbyName('flag_jz').asString,
fieldbyName('certificate').asString,
fieldbyName('cert_Num').asString,
fieldbyName('deadline').ASString]);
end;

setComplete;
finally
Query.Close;
FreeAndNil(Query);
end;

end;

//连接数据库
procedure TMTSObject.ConnectionDb;
begin
if not Assigned(connDB) then
ConnDB:=TADOConnection.Create(nil);
connDB.connectionString:=Format(sLinkSQLDB,[readRegistry('MachineName'),
readRegistry('DBName'),readRegistry('UserName'),readRegistry('password')]);
try
connDB.Close;
ConnDB.LoginPrompt:=false;
ConnDB.Connected:=true;
except
end;

end;

procedure TMTSObject.Initialize;
begin
Inherited;
ConnectionDb;
end;

//判断当前值是否符合要求,返回错误信息
function TMTSObject.CheckRequest(const value: WideString): WideString;
begin

end;

function TMTSObject.ExecutePay(const EndDate,
TheCar: WideString): WideString;
var
Query:Tadoquery;
enddatetime:Tdatetime;
spvehicle:TwebVehicle;
begin
result:='';
Query:=nil;
try
Query:=Tadoquery.Create(nil);
Query.Connection:=ConnDB;
with Querydo
begin
close;
Sql.Clear;
Sql.text:='select * from vehicle where car_num=:car_num';
Parameters.ParamByName('car_num').Value:=thecar;
prepared;
Open;
spvehicle.CarNum:=thecar;
spvehicle.CarType:=fieldbyname('flag_kh').AsString;
if spvehicle.CarType='1' then
spvehicle.Seat_hd:=fieldbyname('seat_f').asfloat
else
spvehicle.Seat_hd:=fieldbyname('load_hd').asfloat;
spvehicle.DeadLine:=fieldbyname('deadline').AsDateTime;
spvehicle.startdate:=fieldbyname('deadline').asdatetime+1;
spvehicle.Certificate:=fieldbyname('Certificate').asstring[1];
end;

enddatetime:=strTodatetime(enddate);
spvehicle.monthnumber:=returnmonth_number(spvehicle.startdate,enddatetime);
spvehicle.xuNnumber:=returnxuN_number(spvehicle.startdate,enddatetime);
spvehicle.standard:=RETURNSF_STANDARD(spvehicle.cartype,query);
spvehicle.pay_yl:=(spvehicle.standard*spvehicle.seat_hd*spvehicle.monthnumber) //月金额
+(round((spvehicle.standard*spvehicle.seat_hd)/3)*spvehicle.xuNnumber);
//旬金额
result:=format(TheCarinfopayContent,[floatTostr(spvehicle.pay_yl)]);

setComplete;
finally
Query.close;
Query.free;
end;


end;

initialization
TAutoObjectFactory.Create(ComServer, TMTSObject, Class_MTSObject,
ciMultiInstance, tmApartment);
CoInitialize(nil);
finalization
CoUninitialize;
 
无话可说,“踢”就一个字!
 
帮你踢,最近视力下降,看什么都头疼,所以不帮你看代码了,我帮你踢.
我原来也用DELPHI写ASP组件,连接的也是SQL或ACCESS,一直使用正常,呵呵...
 
多谢楼上的,代码不多,可以不用看其中的处理内容,只要看对象、变量是否关闭释放。
不过我实在看不出““DAX错误,对象打开时不允许操作” 这个对象是什么对象?
 
解决了!
 
多谢snowsky捧场,
 
后退
顶部