Home > Net >  App cannot gather column names from the db
App cannot gather column names from the db

Time:11-01

I have the following construction Delphi Form > ADO Connection > Otero ODBC Driver > RBase database

(ignore please exotic names)

From the user's logic side, it's all classic: ADO Connection > ADO Query > DataSource > DBGrid

This construction works perfectly on majority of the machines, but one. On the machine, when it does not work as expected, ADO return columns descriptions instead of columns names.

Normally it's like this

Select * from SystemUsers
 SystemUserId SystemUserName                                               
 ------------ ------------------------------------------------------------ 
            1 Administrator

but on the problematic machine I'm getting

 SystemUserId System Autonumber Numero unico de identificacao da Collection FK
 ------------------------------ ------------------------------------------------------------ 
                              1 Administrator

The problematic system is Windows 2019 - but on other Windows 2019 the same app works well. I can take the app ape copy to any other machine, and it works as expected. The machine has installed the same version of the DB and ODBC driver.

As effect, when I call

myAdoQuery.FieldByName('SystemUserId').asInteger ....

I'm getting error:

Field SystemUserId does not exist

I tried naming columns

Select SystemUserId as mycolumn from SystemUsers

... no luck

I tried adding fields to Fields editor - same effect.

I could call fields by its indexes (Field[i]), but this mean re-engineering entire app.

Does anybody know what could go wrong here??

CodePudding user response:

So it turned out, that there was a difference in database server versions (I thought it was the same, but there was a difference). We have updated it and all the problems vanished.

thank you all

CodePudding user response:


You can get the Field-Names of a Table with the following piece of Code:
procedure TestTable1;
var cnt   : Integer;
    msgStr: String;
begin
try
  msgStr := '';
  with Table1 do
  begin
    Close;
    DatabaseName := '';
    TableName := OpenDialog1.FileName;
    Open;

    for cnt := 0 to Table1.FieldDefs.Count - 1 do
    msgStr := msgStr   Table1.Fields.Fields[cnt].FieldName;

    Close;
    ShowMessage(msgStr);
  end;
except
  on E: Exception do
  begin
    ShowMessage('Exception occur:'   #13#10   E.Message);
  end;
end;

This will display all Field-Names in Table1

Hope this helps Jens

  • Related