首页 > 代码库 > 使用Unidac内置连接池
使用Unidac内置连接池
第一步:
放一个TUniconnection并设置相关属性
之后直接使用TUniconnection对象即可
跟踪unidac源码uni单元1540行中可以看到
Connect方法调用CreateIConnection
procedure TUniConnection.CreateIConnection;var Connection: TCRConnection; ConnectionParameters: TCRConnectionParameters; procedure SetSpecificObjectProps(SetAllProps: boolean); begin FProvider.SetObjectProps(Connection, FSpecificOptions.Values, SetAllProps); FSpecificOptions.IsModified := False; end;begin CheckProvider; Connection := FIConnection; if Connection = nil then begin if Pooling and FProvider.IsPoolingSupported then begin ConnectionParameters := FProvider.GetConnectionParametersClass.Create; try ConnectionParameters.MinPoolSize := PoolingOptions.MinPoolSize; ConnectionParameters.MaxPoolSize := PoolingOptions.MaxPoolSize; ConnectionParameters.ConnectionLifeTime := PoolingOptions.ConnectionLifetime; ConnectionParameters.Validate := PoolingOptions.Validate; ConnectionParameters.Username := Username; ConnectionParameters.Password := Password; ConnectionParameters.Server := Server; ConnectionParameters.IOHandler := FIOHandler; ConnectionParameters.OnError := DoError; if FProvider.IsDatabaseSupported then //upd1 ConnectionParameters.SetProp(prDatabase, FDatabase); if FProvider.IsPortSupported then ConnectionParameters.SetProp(prPort, Port); FProvider.SetObjectProps(ConnectionParameters, SpecificOptions, True); Connection := FProvider.GetConnectionPoolingManagerClass.GetConnection( ConnectionParameters, TUniSQLMonitor); finally ConnectionParameters.Free; end; end else begin Connection := GetIConnectionClass.Create; Connection.IOHandler := FIOHandler; if FProvider.IsDatabaseSupported then Connection.SetProp(prDatabase, FDatabase); if FProvider.IsPortSupported then Connection.SetProp(prPort, Port); end; Connection.SetProp(prDisconnectedMode, Options.DisconnectedMode); Connection.SetProp(prEnableBCD, Options.EnableBCD); {$IFDEF VER6P} {$IFNDEF FPC} Connection.SetProp(prEnableFMTBCD, Options.EnableFMTBCD); {$ENDIF} {$ENDIF} Connection.SetProp(prDefaultSortType, Variant(Options.DefaultSortType)); // if connection is just created we need to set all options SetSpecificObjectProps(True); SetIConnection(Connection); end; if FSpecificOptions.IsModified then SetSpecificObjectProps(False);end;
使用Unidac内置连接池
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。