Schema constraint violation on SQL Server 2008 R2
Posted: Wed 14 May 2014 06:48
Hi,
I am getting the following exception on SQL Server 2008 R2:
The code is:
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:
I am getting the following exception on SQL Server 2008 R2:
The same executable works just fine on SQL Server 2014.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 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;
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;