[Lazarus] odbc driver
Michael Van Canneyt
michael at freepascal.org
Mon Feb 6 14:37:43 CET 2023
On Mon, 6 Feb 2023, Larry Dalton via lazarus wrote:
> 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');
This should probably be
ODBCCOnnection1.DatabaseName:=ExtractFilePath(Application.ExeName)+'MyAccess.accdb';
Michael.
More information about the lazarus
mailing list