1. Connecting to the SQL Server database
Procedure Tform1.button1click (Sender:tobject);
Var
P:tsqlconnection;
Begin
Try
P: = tsqlconnection.create (nil);
Try
P.connectionname: = ' mssqlconnection ';
P.drivername: = ' MSSQL ';
P.getdriverfunc: = ' getsqldrivermssql ';
P.keepconnection: = true;
P.loginprompt: = False;
P.libraryname: = ' dbxmss.dll ';
P.vendorlib: = ' sqlncli10.dll ';
p.params.values[' Database ': = ' newvisiontest ';
p.params.values[' HostName ': = ' 192.168.1.250 ';
p.params.values[' user_name ': = ' sa ';
p.params.values[' Password ': = ' sa ';
P.params.add (' Getdriverfunc=getsqldrivermssql ');
P.params.add (' Libraryname=dbxmss.dll ');
P.params.add (' Vendorlib=sqlncli10.dll ');
P.params.add (' Vendorlibwin64=sqlncli10.dll ');
P.params.add (' maxblobsize=-1 ');
P.params.add (' Osauthentication=false ');
P.params.add (' preparesql=true ');
P.params.add (' schemaoverride=sa.dbo ');
P.params.add (' Drivername=mssql ');
P.params.add (' blobsize=-1 ');
P.params.add (' isolationlevel=readcommitted ');
P.params.add (' OS authentication=false ');
P.params.add (' Prepare sql=false ');
P.params.add (' connecttimeout=60 ');
P.params.add (' Mars_connection=false ');
P.connected:=true;
Except
On E:exception do
Raise Exception.create (' Database connection not on ');
End
Except
On E:exception do
Begin
Exit;
End
End
End
2. Connecting a middle-tier server
function Tconnthread.connremotesvr (cn:tsqlconnection; const hostname, UserName,
password:string; Const Port:integer): Boolean;
Begin
Try
cn. Close;
cn. DriverName: = ' datasnap ';
cn. Loginprompt: =false;
Cn.connectionname: = ' datasnapconnection ';
cn. Params.clear;
cn. Params.add (' Drivername=datasnap ');
CN.PARAMS.ADD (' hostname= ' +hostname);
CN.PARAMS.ADD (' port= ' +inttostr (Port));
CN.PARAMS.ADD (' user_name= ' +username);
CN.PARAMS.ADD (' password= ' +password);
cn. Open;
Result: =true;
Except
Result: =false;
End
End
Tsqlconnection Dynamic Connection