[Lazarus] Fwd: odbc driver
Larry Dalton
larrydalton71 at gmail.com
Tue Feb 7 02:05:31 CET 2023
Sent from my iPhone
Begin forwarded message:
> From: Larry Dalton <larrydalton71 at gmail.com>
> Date: February 6, 2023 at 08:27:23 EST
> To: Lazarus mailing list <lazarus at lists.lazarus-ide.org>
> Subject: odbc driver
>
>
> Using lazrus 2.2 ORC1-fpc-3.2.2-win64
> error message: Project MyAccessPractice raised exception class EODBCException with message
> 'Could not connect with connection string'DRIVER=[Microsoft Access Driver(*.mdb,*.accdb)];
> DBQ=C:\Lazarus_MSAccess\MyAccess.accdb;' ODBC error details: LastReturnCode:SQL-ERROR;Record1:SqlState:IM4002;NativeError 0; Message:[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified;
>
> Here is the code, copied from internet
>
> unit AccessUnit;
> {$mode objfpc}{$H+}
> interface
> uses
> Classes, SysUtils, odbcconn, SQLDB, DB, Forms, Controls, Graphics, Dialogs,
> DBGrids, StdCtrls;
> type
> { TForm1 }
> TForm1 = class(TForm)
> Button1: TButton;
> DataSource1: TDataSource;
> DBGrid1: TDBGrid;
> Label1: TLabel;
> ODBCConnection1: TODBCConnection;
> SQLQuery1: TSQLQuery;
> SQLTransaction1: TSQLTransaction;
> procedure Button1Click(Sender: TObject);
> private
> public
> end;
> var
> Form1: TForm1;
>
> implementation
>
> {$R *.lfm}
>
> { TForm1 }
>
> procedure TForm1.Button1Click(Sender: TObject);
> begin
> ODBCConnection1.Driver:='Microsoft Access Driver (*.mdb,*.accdb)';
> ODBCCOnnection1.params.add('DBQ='+ExtractFilePath(Application.ExeName)+'MyAccess.accdb');
> ODBCConnection1.Connected:=TRUE;
> ODBCConnection1.KeepConnection:=TRUE;
>
> SqlTransaction1.DataBase:=OdbcConnection1;
>
> SqlQuery1.DataBase:=ODBCConnection1;
> SQLQuery1.UsePrimaryKeyAsKey:=False;
> SqlQuery1.SQL.Text:='Select * FROM Student';
>
> Datasource1.DataSet:=Sqlquery1;
> DBGrid1.DataSource:=DataSource1;
>
> If ODBCConnection1.Connected then
> begin
> label1.Caption:='Connected';
> end;
>
> SqlQuery1.Open;
> end;
> end.
>
> Current MS Access Driver
> Microsoft Access Driver (*.mdb,*,accdb) Version 16:00 15928020006
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20230206/69627f4a/attachment-0001.htm>
More information about the lazarus
mailing list