在 sqlite/delphi 中切换连接中的数据库文件必须做什么
What has to be done to switch database file in connection in sqlite/delphi
我希望这不是一些令人尴尬的用户错误,但这里是:
我想更改连接的数据库参数并重新打开它。此代码继续显示(并允许编辑)原始 table 连接而不是刷新。我必须调用某种 'flush' 或刷新吗?
dmMain.conMain.close;
dmMain.conMain.Params.Values['Database'] := secondDatabase;
dmMain.conMain.Open;
dmMain.tblTimings.Active := true;
我随后尝试 conMain.Connected := false 没有效果。
根据 Delphi 文档,您需要 ATTACH
现有连接的第二个数据库。
dmMain.ConMain.ExecSQL('ATTACH '+QuotedStr(secondDatabase)+ ' as SecondDB');
要删除数据库,请使用 DETACH
完整文档在这里:http://docwiki.embarcadero.com/RADStudio/Seattle/en/Using_SQLite_with_FireDAC
这不应该发生(所有链接的数据集都应该关闭),所以我将其称为错误(您在代码中做对了)。见Close方法说明:
TCustomConnection.Close
Closes the connection.
Call Close to disconnect from the remote source of database
information. Before the connection component is deactivated, all
associated datasets are closed. Calling Close is the same as setting
the Connected property to false.
In most cases, closing a connection frees system resources allocated
to the connection.
Note: If a previously active connection is closed and then reopened,
any associated datasets must be individually reopened; reopening the
connection does not automatically reopen associated datasets.
我希望这不是一些令人尴尬的用户错误,但这里是:
我想更改连接的数据库参数并重新打开它。此代码继续显示(并允许编辑)原始 table 连接而不是刷新。我必须调用某种 'flush' 或刷新吗?
dmMain.conMain.close;
dmMain.conMain.Params.Values['Database'] := secondDatabase;
dmMain.conMain.Open;
dmMain.tblTimings.Active := true;
我随后尝试 conMain.Connected := false 没有效果。
根据 Delphi 文档,您需要 ATTACH
现有连接的第二个数据库。
dmMain.ConMain.ExecSQL('ATTACH '+QuotedStr(secondDatabase)+ ' as SecondDB');
要删除数据库,请使用 DETACH
完整文档在这里:http://docwiki.embarcadero.com/RADStudio/Seattle/en/Using_SQLite_with_FireDAC
这不应该发生(所有链接的数据集都应该关闭),所以我将其称为错误(您在代码中做对了)。见Close方法说明:
TCustomConnection.Close
Closes the connection.
Call Close to disconnect from the remote source of database information. Before the connection component is deactivated, all associated datasets are closed. Calling Close is the same as setting the Connected property to false.
In most cases, closing a connection frees system resources allocated to the connection.
Note: If a previously active connection is closed and then reopened, any associated datasets must be individually reopened; reopening the connection does not automatically reopen associated datasets.