Hi guys
I have a problem with firebird embedded. When I compile app I have got error
Project project1 raised exception class 'EDatabaseError' with message
DataSource1: Circular datasource reference are not allowed
I tried everything and search the forum but I have no idea, what cause it.
My code is
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, DB, IBConnection, SQLDBLib, SQLDB, Forms,
Controls, Graphics, Dialogs, DBCtrls, DBGrids, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
IBConnection1: TIBConnection;
Label1: TLabel;
SQLDBLibraryLoader1: TSQLDBLibraryLoader;
SQLQuery1: TSQLQuery;
SQLTransaction1: TSQLTransaction;
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
DataPath:AnsiString;
FirebirdPath: AnsiString;
begin
DataSource1.DataSet := SQLQuery1;
DataPath := ExtractFilePath(Application.ExeName) + 'data\employee.fdb'; // database
FirebirdPath := ExtractFilePath(Application.ExeName) + 'firebird\fbclient.dll'; // database
SQLDBLibraryLoader1.ConnectionType:='Firebird';
SQLDBLibraryLoader1.LibraryName:=FirebirdPath;
SQLDBLibraryLoader1.Enabled:=True;
IBConnection1.DatabaseName:=DataPath;
IBConnection1.Connected:=True;
SQLQuery1.SQLConnection:=IBConnection1;
SQLQuery1.SQL.Text:='select RDB$Relation_Name from RDB$RELATIONS where RDB$Relation_Name not like ''%$%''';
SQLQuery1.Open;
SQLQuery1.Active:=True;
SQLTransaction1.DataBase:=IBConnection1;
SQLQuery1.Transaction:=SQLTransaction1;
DBNavigator1.DataSource := DataSource1;
DBGrid1.DataSource := DataSource1;
end;
end.
Thanks
The issue is that you're assigning `DataSource1.DataSet := SQLQuery1` before setting it to `DBNavigator1` and `DBGrid1`. To fix it, just change the order:
```pascal
SQLQuery1.Open;
DataSource1.DataSet := SQLQuery1; // Set DataSource after opening the query
DBNavigator1.DataSource := DataSource1;
DBGrid1.DataSource := DataSource1;
```
This should solve the circular reference error.