procedure TForm1.Button1Click(Sender: TObject);
Var oConn : IADPhysConnection;
oCmd : IADPhysCommand;
oTab : TADDatSTable;
i, j : Integer;
s : String;
begin
// 1. open AnyDAC's ADPhysManager
ADPhysManager.Open;
With ADPhysManager.ConnectionDefs.AddConnectionDef Do
Begin
Name := 'My_DB';
DriverID := 'MSAcc';
Database := '.\db\Test.mdb';
Params.Add ('Tracing=True');
End;
// 2. create connection
ADPhysManager.CreateConnection('My_DB', oConn);
oConn.Open;
// 3. create command and prepare SELECT statement
oConn.CreateCommand(oCmd);
oCmd.Prepare('select str_Kuenstler from tbl_Kuenstler');
oCmd.Open;
// 4. fetch rows from RDBMS to DatSTable
oTab := TADDatSTable.Create;
oCmd.Define (oTab);
oCmd.Fetch (oTab);
// 5. print rows
Memo1.Clear;
for i := 0 to oTab.Rows.Count - 1 Do
Begin
s := '';
for j := 0 To oTab.Columns.Count - 1 Do
s := s + oTab.Rows[I].GetData(J) + ' ';
Memo1.Lines.Add(s);
end;
// 6. free resources
oCmd.Unprepare;
oCmd.Close;
oConn.Close;
oTab.Free;
oConn := Nil;
oCmd := Nil;
ADPhysManager.Close(True);
end;
I have just asked to you at my site.
1) I have just checked your demo with AnyDAC v 1.2.5 and
I does not see any issues. Could you download v 1.2.5 and try
again, please ? Then, please, let me know the result.
2) Also, you can replace:
> // 6. free resources
> oCmd.Unprepare;
> oCmd.Close;
>
> oConn.Close;
>
> oTab.Free;
> oConn := Nil;
> oCmd := Nil;
>
> ADPhysManager.Close(True);
with:
// 6. free resources
oTab.Free;
ADPhysManager.Close(False);
That means, Delphi runtime will wipe out unused interfaces
for you. And Close(False) will close manager right after all
connection interfaces will be released, but not blocking caller
until that moment.
Regards,
Dmitry
--
Dmitry Arefiev - www.da-soft.com
AnyDAC - Oracle, MySQL, MSSQL, MSAccess, IBM DB2, Sybase
ASA, DbExpress, ODBC freeware data access framework
gs-soft AG - www.gs-soft.com
SAPx - Delphi to SAP R/3 direct access
Saphir - SAP R/3 metadata at your fingertips
MetaBase - ERWIN model in Delphi applications