0

I'm trying to access into a database in SQL Server 2019 Express from my old Delphi 7 project that still using BDE and SQL Server as Driver name (for migration only). With the db1 (tDatabase) setting like this:

DATABASE NAME=master
USER NAME=sa
ODBC DSN=base6280 *// (that I've created first)*
OPEN MODE=READ/WRITE
PASSWORD=abc

But after connecting to MASTER database, when I ran this query (tQuery):

cbDBname.Items.Clear;

Q := TQuery.Create(nil);
try
  Q.DataBaseName := 'MASTER';

  Q.SQL.Text := ' SELECT NAME as DBxxx 
                  FROM MASTER.DBO.SYSDATABASES  
                  ORDER BY Name DESC ';
  Q.Open;
  while not Q.Eof do
  begin
     cbDBname.Items.Add(Q.FieldByName('DBxxx').AsString);
     Q.Next;
  end;

I get an error :

enter image description here

Can somebody here help me to figure out? How to handle this error?

Thanks for your attention and any response (beside bde has been depreciated) is much more expected.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jasen
  • 1
  • 2
  • sorry, the error message was : .exe raised exception class EDatabaseError with message 'Field 'DBxxx' not found'. Process stopped. ( at line : cbDBname.Items.Add(Q.FieldByName('DBxxx').AsString); ) – Jasen Apr 28 '23 at 16:49
  • thanks @marc_s for your revision, sorry my english is poor – Jasen Apr 29 '23 at 07:58
  • well guys, I have figured out... the problem is BDE not support SYSNAME data type, so I have to change the query to be like this : Q.SQL.Text := ' SELECT CAST(NAME as varchar(128)) as DBxxx FROM SYS.DATABASES ORDER BY Name DESC '; Q.Open; done... it worked, thanks – Jasen May 01 '23 at 00:17
  • 1
    Honestly, BDE was deprecated almost 20 years ago and Delphi 7 has well over 15 years... it's a miracle (or the proof Delphi is a great tool) that this works ;-) – Marco Cantù May 03 '23 at 08:30

0 Answers0