0

With the ADO components in Delphi 2007 through Delphi 11.2, I have the following problem:

My DBMS is Microsoft SQL Server. The "required" attribute is always false, even if the field is "NOT NULL". The issue happens with all 3 generations of ADO drivers tested with all 3 generations of Microsoft SQL Server (SQLOLEDB, SQLNCLI11, MSOLEDBSQL).

procedure TForm1.Button1Click(Sender: TObject);
begin
  ADOConnection1.ConnectionString := 'Provider=MSOLEDBSQL;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AKTEST_1;Data Source=SERVER1\XYZ,49010';
  ADOConnection1.LoginPrompt := false;
  ADOConnection1.Connected := true;
  ADOTable1.Connection := ADOConnection1;
  ADOTable1.TableName := 'TABLENAME';
  ADOTable1.Active := true;
  if ADOTable1.FieldByName('NOT_NULL_FIELDNAME').Required then showmessage('Field is not null') else showmessage('Field is null');
end;

Is there anything I can do, or is this a bug in Delphi?

Daniel Marschall
  • 3,739
  • 2
  • 28
  • 67
  • 1
    You can set the attribute yourself on an as-needed basis. If you forget to do this at the field level, then not null field-level constraint will raise an exception anyway, which you can trap and report to the user appropriately. – Freddie Bell Mar 29 '23 at 10:55
  • I can't imagine `Data Source=SERVER1\XYZ,49010` is helping. Have you tried `Data Source=SERVER1\XYZ` (instance name) or `Data Source=SERVER1,49010` (port number) instead? – AlwaysLearning Mar 29 '23 at 12:37
  • 1
    maybe this can help you: http://www.delphigroups.info/2/06/217947.html – whosrdaddy Mar 29 '23 at 13:20

0 Answers0