一,前端对数据库的操作主要通过4个接口函数来实现(TCP通信):
用TSQLConnection 连接服务端:(引用单元 DbxCompressionFilter,主要服务端启用压缩过滤器有)
1,代码静态设置:
2,生成服务器代理类以便调用
3,生产环境代码连接:
var
errmsg: string;
begin
try
SQLConnection1.Close;
SQLConnection1.Connected := false;
SQLConnection1.DriverName := 'DataSnap';
SQLConnection1.Params.Values['Port'] := '8011';
SQLConnection1.Params.Values['HostName'] := '127.0.0.1';
SQLConnection1.Params.Values['DSAuthenticationUser'] := '';
//通信秘钥
SQLConnection1.Params.Values['DSAuthenticationPassword'] := '8889';
//自定客户端标识信息
SQLConnection1.Params.Values['ClientInfo'] := 'mes';
//设置与服务端一样的缓冲区容量
SQLConnection1.Params.Values['BufferKBSize'] := '128';
SQLConnection1.Connected := true;
// ser: TFtcpserClient; 需要引用生成的类文件
ser := TFtcpserClient.Create(SQLConnection1.DBXConnection);
except
on ee: exception do
begin
errmsg := ee.Message;
if errmsg = Remoteerror + '403' then
showmessage('没权限')
else if errmsg = Remoteerror + '405' then
showmessage('超出连接数')
else if pos('socket error', errmsg) > 0 then
begin
showmessage('无法连接服务器,请重新进入系统试试 ');
end
else
showmessage('error: ' + errmsg);
end;
end;
end;