数据库连接组件,支持三种连接方式:
1.持久定义(有一个唯一名称和一个配置文件,可以由FDManager管理)
例:
uses
FireDAC.Comp.Client, FireDAC.Stan.Intf;
var
oDef: IFDStanConnectionDef;
begin
oDef := FDManager.ConnectionDefs.AddConnectionDef;
oDef.Name := 'MSSQL_Connection';
oDef.DriverID := 'MSSQL';
oDef.Server := '127.0.0.1';
oDef.Database := 'Northwind';
oDef.OSAuthent := True;
oDef.MarkPersistent;
oDef.Apply;
.....................
FDConnection1.ConnectionDefName := 'MSSQL_Connection';
FDConnection1.Connected := True;
end;
2.私有定义(有一个唯一名称可以由FDManager管理,无配置文件)
例:
var
oParams: TStrings;
begin
oParams := TStringList.Create;
oParams.Add('Server=127.0.0.1');
oParams.Add('Database=Northwind');
oParams.Add('OSAuthent=Yes');
FDManager.AddConnectionDef('MSSQL_Connection', 'MSSQL', oParams);
.....................
FDConnection1.ConnectionDefName := 'MSSQL_Connection';
FDConnection1.Connected := True;
end;
3.临时定义(没有名称和配置文件,不能由FDManager管理,运行时将参数写入params属性)
例:
uses
FireDAC.Phys.IBDef, FireDAC.Phys.IBWrapper;
......
FDConnection1.DriverName := 'IB';
with FDConnection1.Params as TFDPhysIBConnectionDefParams do begin
Protocol := ipTCPIP;
Server := '127.0.0.1';
Database := 'c:\IB\employee.gdb';
UserName := 'sysdba';
Password := 'masterkey';
end;
FDConnection1.Connected := True;
2. FDConnection1.ConnectionString := 'DriverID=MSSQL;Server=127.0.0.1;Database=Northwind;User_name=sa';
FDConnection1.Connected := True;)
end;
|