第一步:
放一个TUniconnection并设置相关属性
之后直接使用TUniconnection对象即可
跟踪unidac源码uni单元1540行中可以看到
Connect方法调用CreateIConnection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
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
<span style="color: #ff0000;"><strong>
if
Pooling
and
FProvider
.
IsPoolingSupported
then
begin
</strong></span>
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
);
<span style="color: #ff0000;"> Connection := FProvider
.
GetConnectionPoolingManagerClass
.
GetConnection(
ConnectionParameters, TUniSQLMonitor);</span>
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
;
|
http://www.cnblogs.com/pengshaomin/p/4126662.html