我使用 Zeoslib 组件与 SQLite 数据库文件交互。我的一个文件夹中有几个 SQLite 数据库文件。因此,我希望能够使用 Zeoslib 组件打开其中任何一个。然而,它不会让我这么做。它成功打开第一个数据库,但此后我打开的任何数据库文件都会出现访问冲突错误。对于我的一生,我根本无法弄清楚为什么。
这是我打开数据库文件的方法。
procedure TMainFrm.Open1Click(Sender: TObject);
var currdb:string;
begin
OpenDlg.InitialDir := BaseDir;
if OpenDlg.Execute = true then
begin
currdb := Extractfilename(OpenDlg.FileName);
DataModule1.ZConnection1.Disconnect;
DataModule1.ZConnection1.Protocol := 'SQLite-3';
DataModule1.ZConnection1.Database :=baseDir + currdb;
DataModule1.Query1.SQL.Clear;
DataModule1.Query1.SQL.Add('SELECT * FROM MyTable'); // <<<<--- ZConnection1 is Query1 database connection.
DataModule1.ZConnection1.Connect; // <<<<<-------Here is where I get ACCESS VIOLATION all the time.
UpdateGrid; // <<<<<<<----- Here is where the Query is executed and the DBGrid is updated.
end;
end;
我不知道这是为什么。这是否意味着我无法使用 Zeoslib 组件从另一个数据库切换数据库?
最佳答案
问题出在 TZConnection.Protocol
值的大小写上。将 Protocol
值从 SQLite-3
更改为 sqlite-3
.
关于database - Zeoslib 不允许切换数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26890563/