1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | procedure TForm1 . FormCreate(Sender: TObject); var oParams: TStrings; begin with FDManager do begin oParams := TStringList . Create; oParams . Add( 'Database=xxx.xxx.xxx.xxx:1521/orac' ); oParams . Add( 'Pooled=True' ); oParams . Add( 'DriverID=Ora' ); oParams . Add( 'User_Name=username' ); oParams . Add( 'Password=password' ); oParams . Add( 'OSAuthent=No' ); oParams . Add( 'POOL_MaximumItems=1' ); //搞一个测试看看 FDManager . AddConnectionDef( 'Ora_Pooled' , 'Ora' , oParams); FreeAndNil(oParams); end ; end ; |
这样就可以定义一个 Private的连接了
另外,看了文档,也明白了,连接定义FDConnectionDefs.ini的名字可以自己起,然后设置上 FDManager的ConnectionDefFileName就可以,这样还灵活一点点。
这个【Private】的意思,没看明白,因为就算【Persistent】也肯定是不能跨Exe来Pool的。
连接池的使用,直接定义一个conn,然后设置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | procedure TForm1 . Button1Click(Sender: TObject); var conn: TFDCustomConnection; begin conn := TFDCustomConnection . Create( nil ); conn . ConnectionDefName := 'Ora_Pooled' ; FDQuery1 . Connection := conn; FDQuery1 . Active := True ; conn := TFDCustomConnection . Create( nil ); conn . ConnectionDefName := 'Ora_Pooled' ; FDQuery2 . Connection := conn; FDQuery2 . Active := True ; end ; |
POOL_MaximumItems定义的值时,conn的发起连接时就会报异常了。
联系客服