以编程方式设置 TSQLConnection 属性
Programmatically set TSQLConnection properties
使用 TSQLConnection 组件,如果我将 Driver 属性 设置为 DataSnap 有没有办法在代码中手动设置该驱动程序的属性?
例如CommunicationProtocol 或 CommunicationIPVersion.
如有任何帮助,我们将不胜感激。
谢谢,
嗯,这并不像 SilverWarior 描述的那么简单。问题是这些属性是特定于驱动程序的,不能直接从 TSQLConnection 访问。好的,这是一个方法:
var
dbxProps: TDBXDatasnapProperties;
begin
Assert(SQLConnection1.DriverName = 'DataSnap', 'Driver must be DataSnap');
dbxProps := SQLConnection1.ConnectionData.Properties as TDBXDatasnapProperties;
dbxProps.CommunicationProtocol := 'tcp/ip';
dbxProps.CommunicationIPVersion := 'IPv6';
end;
您可以为此目的使用 TSQLConnection.Params
属性:
Lists the connection parameters.
Params is a TStrings object listing the connection parameters. Each entry in the string list has the form
Name=Value
where Name is the name of the parameter and Value is its value. If you are using named connection configurations (the ConnectionName property), the values for each parameter are loaded from the dbxconnections.ini file when you set ConnectName
.
At design time, you can set parameter values using the string list editor by double-clicking the Params property in the Object Inspector. Any new values you set override the values loaded when you set ConnectionName, unless you load the connection configuration at run time using LoadParamsFromIniFile or LoadParamsOnConnect.
The particular parameters that appear depend on the database server. The Params property is initialized to include a string for each parameter when you set the DriverName
property. One particular parameter, Database
, is required for all servers. Its value depends on the server you are using. For example, with InterBase, Database
is the name of the .gdb file, while with MySQL, it is the database name that was assigned by the CREATE DATABASE
command.
例如:
SQLConnection1.DriverName := 'DataSnap';
SQLConnection1.Params.Values['CommunicationProtocol'] := 'tcp/ip';
SQLConnection1.Params.Values['CommunicationIPVersion'] := 'IPv6';`
使用 TSQLConnection 组件,如果我将 Driver 属性 设置为 DataSnap 有没有办法在代码中手动设置该驱动程序的属性?
例如CommunicationProtocol 或 CommunicationIPVersion.
如有任何帮助,我们将不胜感激。
谢谢,
嗯,这并不像 SilverWarior 描述的那么简单。问题是这些属性是特定于驱动程序的,不能直接从 TSQLConnection 访问。好的,这是一个方法:
var
dbxProps: TDBXDatasnapProperties;
begin
Assert(SQLConnection1.DriverName = 'DataSnap', 'Driver must be DataSnap');
dbxProps := SQLConnection1.ConnectionData.Properties as TDBXDatasnapProperties;
dbxProps.CommunicationProtocol := 'tcp/ip';
dbxProps.CommunicationIPVersion := 'IPv6';
end;
您可以为此目的使用 TSQLConnection.Params
属性:
Lists the connection parameters.
Params is a TStrings object listing the connection parameters. Each entry in the string list has the form
Name=Value
where Name is the name of the parameter and Value is its value. If you are using named connection configurations (the ConnectionName property), the values for each parameter are loaded from the dbxconnections.ini file when you set
ConnectName
.At design time, you can set parameter values using the string list editor by double-clicking the Params property in the Object Inspector. Any new values you set override the values loaded when you set ConnectionName, unless you load the connection configuration at run time using LoadParamsFromIniFile or LoadParamsOnConnect.
The particular parameters that appear depend on the database server. The Params property is initialized to include a string for each parameter when you set the
DriverName
property. One particular parameter,Database
, is required for all servers. Its value depends on the server you are using. For example, with InterBase,Database
is the name of the .gdb file, while with MySQL, it is the database name that was assigned by theCREATE DATABASE
command.
例如:
SQLConnection1.DriverName := 'DataSnap';
SQLConnection1.Params.Values['CommunicationProtocol'] := 'tcp/ip';
SQLConnection1.Params.Values['CommunicationIPVersion'] := 'IPv6';`