私は dbexpress を初めて使用し、実行時に SQL ホスト名の TSQLConnection パラメーターを設定する方法がわかりません。プログラムをクライアント システムにインストールすると、開発中に入力した開発システムから TSQLConnectionHost がまだホストを読み取っています。
3 に答える
TSQLConnection.Params
は typeTStrings
です。つまり、String
アイテムのセットを保持します。TSQLConnection の場合、Params は一連のName=Value
ペアを保持します。ここName
で、 はパラメータ名で、Value
はそのパラメータ値です。特定のパラメータの値を読み取るには、次を使用します。
var
s: String;
...
s := SQLConnection1.Params.Values['ParamName'];
特定のパラメータに値を割り当てるには、次を使用します。
SQLConnection1.Params.Values['ParamName'] := 'NewValue';
('ParamName' を実際のパラメーター名に置き換え、'NewValue' を実際の新しい値に置き換えます。)
問題の理由は、アプリを配布する前に SQLConnection とすべてのデータセットを切断していないことです。すべきこと a) すべてのコンポーネントが接続されていないことを確認します。b) SQLConnection のパラメーターを空白に設定します。c) アプリの起動時に、ini ファイルから必要な接続パラメーターを読み取り、それらを SQLConnection に設定します。d) 接続すれば問題ありません。よろしくクリス
I faced this problem a few years ago when I started developing with dbExpress. On my development machine, the databases were in location X whereas the production machines had the databases in location Y. The way I got around this was to store the physical location of the database in the registry (via a small utility program which I wrote) and then use the following code to load the correct value. The location could be stored in an INI file which would require a slight alteration to my code, but that part is less important.
procedure TDm.SQLConnection1BeforeConnect(Sender: TObject);
var
dir: string;
begin
with TRegIniFile.create (regpath) do // this is where I get the physical value
begin
dir:= ReadString ('firebird', progname, '');
free
end;
with sqlconnection1 do
begin
close;
params.values['database']:= dir;
end;
end;