Schema constraint violation on SQL Server 2008 R2

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
anwenkom
Posts: 1
Joined: Wed 14 May 2014 06:33

Schema constraint violation on SQL Server 2008 R2

Post by anwenkom » Wed 14 May 2014 06:48

Hi,
I am getting the following exception on SQL Server 2008 R2:
Project SVP.exe raised exception class EOLEDBError with message 'OLE DB error occurred. Code 80040E21h

Parameter[0] :number - the data value violates the schema's constraint for the column (Status = Bh).'.
The same executable works just fine on SQL Server 2014.

The code is:

Code: Select all

  DataSet1 := CreateQuery('select distinct number as "nummer", behoerde, zusatz, strasse, ' + 'haus_nr, hsnr_zus, behoerde_plz, behoerde_ort, landkreis, land, art, einwohner, internet, wikipedia from behoerdenverzeichnis where (plz = :plz or :plz = '''') and (ort = :ort or :ort = '''')');
  DataSet1.ReadOnly := True;
  DataSource := TDataSource.Create(Self);
  DataSource.DataSet := DataSet1;
  DataSet2 := CreateQuery('select plz, ort from behoerdenverzeichnis where number = :number');
  DataSet2.MasterSource := DataSource;
  DataSet2.ReadOnly := True;
  DataSet2.Open;
Where CreateQuery is a simple function that creates a TMSQuery, sets the connection and assigns SQL.

I found a workaround that works on both 2008 R2 and 2014, but I don't want to change the code in many places. The workaround looks like this:

Code: Select all

DataSet1 := CreateQuery('select distinct number as "nummer", behoerde, zusatz, strasse, ' + 'haus_nr, hsnr_zus, behoerde_plz, behoerde_ort, landkreis, land, art, einwohner, internet, wikipedia from behoerdenverzeichnis where (plz = :plz or :plz = '''') and (ort = :ort or :ort = '''')');
  DataSet1.ReadOnly := True;
  DataSource := TDataSource.Create(Self);
  DataSource.DataSet := DataSet1;
  DataSet2 := CreateQuery('select plz, ort from behoerdenverzeichnis');
  DataSet2.MasterSource := DataSource;
  DataSet2.MasterFields := 'number';
  DataSet2.DetailFields := 'number';
  DataSet2.ReadOnly := True;
  DataSet2.Open;

azyk
Devart Team
Posts: 1057
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Schema constraint violation on SQL Server 2008 R2

Post by azyk » Thu 15 May 2014 15:19

Hi,

Thank you for the information. We have reproduced the problem and will investigate it.

Post Reply