Sign in Join

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

Mailing lists / lazarus / 2010-01

TODBCConnection (Lazarus) vs TDatabase (TurboDelphi 2006)

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

David Viktora

Hi all,

I do have a quite a problem here. I am developing a tool that is supposed to load data from COBOL database (via ODBC driver) into a grid. There is a Settings section there in the application; user can select a proper DSN name of theODBC driver (for there might be more than one driver, each pointing to its own COBOL database) and then test the selected driver by clicking on the Test button.

In Delphi I'm using TDatabase component and Try - Except block for testing:

procedure TfrmNastaveniAplikace.btnTestClick(Sender: TObject);
var
  DatabaseBMD: TDataBase;
begin
  DatabaseBMD := TDataBase.Create(Nil);
  with DatabaseBMD do
  begin
    DatabaseName := 'TestDB';
    LoginPrompt := False;
    SessionName := 'Default';
    Connected := False;
  end;
  if (cmbVyberOdbc.Text  '') then
  begin
    try
      DatabaseBMD.AliasName := cmbVyberOdbcLonskyRok.Text; //here I pass
the DSN of selected ODBC driver to the component
      DatabaseBMD.Connected := True;
      ShowMessage(Connection test successful!'); //I was able to connect
to the database via the driver, say "Hooray" to user
    except
      ShowMessage('Connection test failed.' + #13#10 + 'Check please the
ODBC settings.'); //The connection could not be established, tell the
user about it
    end;
  end;
  DatabaseBMD.Connected := False;
  DatabaseBMD.free;
end;

It works flawlessly under 32b Windows XP/Vista/7. But when I try to launch this application under 64b Windows 7, the code above always end up in the Except part of the block, even though the user still can see and select the driver. For users with 64b Windows 7, I decided to do the tool in Lazarus under my 64b Windows 7 (and then compile it under Lazarus for 32b Windows XP for those using Windows XP). The problem is that Lazarus does not use TDataBase anymore, there is TOdbcConnection component there instead. When I try this:

procedure TfrmNastaveniAplikace.btnTestClick(Sender: TObject);
var
  DatabaseBMD: TODBCConnection;
begin
  DatabaseBMD := TODBCConnection.Create(nil);
  with DatabaseBMD do
  begin
    DatabaseName := cmbSelectOdbcDriver.Text; //here I pass the DSN
    Password := '';
    UserName := '';
    LoginPrompt := False;
    Connected := False;
  end;
  if (cmbOdbcFibuLonskyRok.Text  '') then
  begin
    try
      DatabaseBMD.Connected := True;
      ShowMessage('Connection test successful!'); //Test ODBC was
successful, say "All Green" to user
    except
      ShowMessage('Connection test failed.' + #13#10 + 'Check the ODBC
settings.'); //ODBC test failed, say "Oh sh.t" to user
    end;
  end;
  DatabaseBMD.Connected := False;
  DatabaseBMD.free;
end;

... I always get error message saying "Project raised an exception - External:SIGSEV" (on the line DatabaseBMD.Connected := True). I have been digging in the Lazarus documentation and it seems to me that I should not use the DataBase name property the way I am using it. But there was no closer info on the matter, so I am hoping to get a qualified help from you guys. How else could I do the test (and connect to the database by just passing over a DSN name)?

Used IDEs are: Turbo Delphi 2006, Lazarus 0.9.28.2 with FPC 2.2.4

Thanks in advance for your help.

David Viktora, KIT s.r.o.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100118/9034f5ec/attachment-0001.html>

Reply by email