Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2023-02

odbc driver

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Larry Dalton

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/74d75a92/attachment.htm>

Reply by email

Michael Van Canneyt
to Larry Dalton
Larry Dalton wrote 46 lines
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.

Reply by email

Werner Pamler
to Larry Dalton: Using lazrus 2.2 ORC1-fpc-3.2.2-win64 error message: Project MyAccessPractice raised…
Larry Dalton wrote 9 lines
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; Current MS Access Driver Microsoft Access Driver (*.mdb,*,accdb) Version 16:00 15928020006

I have the same code in one of my test projects, and it is working. A problem could be that you seem to use the 64-bit IDE, but your database could be 32bit: My Access version (2016) only produces 32-bit databases. I get the same error message when I try to open a 32-bit accdb file in the 64-bit application.

Reply by email

Larry Dalton
to Werner Pamler

I wondered about that.

Sent from my iPhone

Show quoted text 19 lines
On Feb 6, 2023, at 18:15, Werner Pamler via lazarus wrote: ?Am 06.02.2023 um 14:27 schrieb Larry Dalton via lazarus: > 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; > > Current MS Access Driver > Microsoft Access Driver (*.mdb,*,accdb) Version 16:00 15928020006 I have the same code in one of my test projects, and it is working. A problem could be that you seem to use the 64-bit IDE, but your database could be 32bit: My Access version (2016) only produces 32-bit databases. I get the same error message when I try to open a 32-bit accdb file in the 64-bit application. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

Larry Dalton
to Larry Dalton

Apparently that isn?t it. Running Access version 2301 64bit

Sent from my iPhone

Show quoted text 25 lines
On Feb 6, 2023, at 18:46, Larry Dalton wrote: ?I wondered about that. Sent from my iPhone > On Feb 6, 2023, at 18:15, Werner Pamler via lazarus wrote: > > ?Am 06.02.2023 um 14:27 schrieb Larry Dalton via lazarus: >> 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; >> >> Current MS Access Driver >> Microsoft Access Driver (*.mdb,*,accdb) Version 16:00 15928020006 > I have the same code in one of my test projects, and it is working. A problem could be that you seem to use the 64-bit IDE, but your database could be 32bit: My Access version (2016) only produces 32-bit databases. I get the same error message when I try to open a 32-bit accdb file in the 64-bit application. > > -- > _______________________________________________ > lazarus mailing list > > https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

Larry Dalton
to Larry Dalton: Using lazrus 2.2 ORC1-fpc-3.2.2-win64 error message: Project MyAccessPractice raised…

Sent from my iPhone

Begin forwarded message:

Show quoted text 73 lines
From: Larry Dalton Date: February 6, 2023 at 08:27:23 EST To: Lazarus mailing list 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>

Reply by email