在三层的服务端我用了一个AdoConnection连接Access数据库,但是如何动态写入如下字符串呢?在哪个事件里呢?我试了在procedure Tdm.RemoteDataModuleCreate(Sender: TObject);事件里写,但是好像不行,有没有哪位兄弟知道?急等中先谢了!
IF AdoConnection.Connected then AdoConnection.Connected := False; AdoConnection.ConnectionString :=' Provider=MSDASQL.1;Password=server; '+
' Persist Security Info=True;User ID=admin;'+
' Extended Properties="DBQ='''+ApplicationPath+'''ShortCut.mdb'+
' ;DefaultDir='''+ApplicationPath+''''+
' ;Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;'+
' FILEDSN='''+ApplicationPath+'''Dsn_DataLink.dsn'+
' ;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;PWD=server;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;";'+
' Initial Catalog='''+ApplicationPath+'''ShortCut'; Try
Conn.Connected := True;
Except
MessageDlg('数据库连接失败!',Mterror,[mbok],0)
end;
IF AdoConnection.Connected then AdoConnection.Connected := False; AdoConnection.ConnectionString :=' Provider=MSDASQL.1;Password=server; '+
' Persist Security Info=True;User ID=admin;'+
' Extended Properties="DBQ='''+ApplicationPath+'''ShortCut.mdb'+
' ;DefaultDir='''+ApplicationPath+''''+
' ;Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;'+
' FILEDSN='''+ApplicationPath+'''Dsn_DataLink.dsn'+
' ;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;PWD=server;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;";'+
' Initial Catalog='''+ApplicationPath+'''ShortCut'; Try
Conn.Connected := True;
Except
MessageDlg('数据库连接失败!',Mterror,[mbok],0)
end;
AdoConnection.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + extractfilepath(application.ExeName) + '\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;'AdoConnection.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;'上面连的是access数据库,你把数据库改下就行了
哪你写的AdoConnection.ConnectionString := ...
根本就没有执行这一句,好像根本也就没有执行。不能得到在C/s结构中在datamodule的Create中执行这句话一样的效果。而且在mainFrm中也不能引用remote data module中的对象。就是在什么时候三层在建立数据模块的时候,可以动态连接数据模块呢。