FireDAC在SQL Server中截断了错误消息

时间:2018-04-05 20:34:17

标签: sql-server delphi firedac

FireDAC在TClientDataset.OnReconcileError中返回截断的消息。消息是

  

[FireDAC] [Phys] [ODBC] [Microsoft] [SQL Server Native Client 11.0] [SQL Server] INSERT语句与FOREIGN KEY约束“FK_NAME”冲突。冲突发生在数据库“DATABASENAME”,表“dbo.TABLENAME”,列''CD

错误来自Datasnap.DBClient.TCustomClientDataSet.ReconcileCallback,参数pErrMessage。调用堆栈的错误:

ucdClientDataSet.TcdClientDataSet.cdInternalReconcile($11E17C90,$E8A8A70,ukInsert,raAbort)
Datasnap.DBClient.TCustomClientDataSet.ReconcileCallback(0,???,2,547,$11DE2990,$12038D90,$11F97F60,nil,$11F98B90,0,???)
MidasLib.DllGetDataSnapClassObject((202032032, 0, 0, (36, 191, 2, 18, 0, 134, 133, 14)),???,(no value))
:006f9a7b DllGetDataSnapClassObject + $1E32A
MidasLib.DllGetDataSnapClassObject((202032032, 0, 0, (36, 191, 2, 18, 0, 134, 133, 14)),???,(no value))
:006f9366 DllGetDataSnapClassObject + $1DC15
MidasLib.DllGetDataSnapClassObject((37671188, 1, 0, (0, 44, 2, 11, 25, 0, 0, 0)),(37671188, 1, 0, (192, 236, 145, 14, 100, 0, 0, 0)),(no value))
:006fa085 DllGetDataSnapClassObject + $1E934
Datasnap.DBClient.TCustomClientDataSet.Reconcile(???)
Datasnap.DBClient.TCustomClientDataSet.ApplyUpdates(0)
ucdClientDataSet.TcdClientDataSet.ApplyUpdates(0)

消息错误代码为547.如果我执行

select * from sysmessages where error = 547 and msglangid = 1033

在SQL Server中,消息为:

  

%ls语句与%ls约束“%。* ls”冲突。该   数据库“%。* ls”发生冲突,表“%。* ls”%ls%。* ls%ls。

修改

要模拟问题,请按以下步骤:

在SQL Server中创建两个表(我使用12.0.2000.8),一个引用另一个

CREATE TABLE TEST_TABLE_A(FIELD_PRIMARYKEY INT NOT NULL) 

ALTER TABLE TEST_TABLE_A ADD CONSTRAINT PK_FIELD_PRIMARYKEY_1 PRIMARY KEY (FIELD_PRIMARYKEY)

CREATE TABLE TEST_TABLE_B(FIELD_FOREIGNKEY INT)

ALTER TABLE TEST_TABLE_B ADD CONSTRAINT FK_FIELD_FOREIGNKEY FOREIGN KEY (FIELD_FOREIGNKEY) REFERENCES TEST_TABLE_A(FIELD_PRIMARYKEY)

在Delphi(10.1 update 2)中,创建一个项目并添加:

TFDConnection:在数据库中配置创建测试表的连接;

TFDQuery:连接FDConnection,并输入SQL文本:“select * from TEST_TABLE_B”;

TDatasetProvider:将Dataset属性连接到FDQuery;

TClientDataset:将ProviderName属性连接到Provider;

TButton:把代码:

  ClientDataSet1.open;
  ClientDataSet1.insert;
  ClientDataSet1.fieldbyname('FIELD_FOREIGNKEY').asinteger := -1;
  ClientDataSet1.post;
  ClientDataSet1.ApplyUpdates(0);

在ClientDataset.OnReconcileError中,添加代码:

  try
    E.RaiseOuterException(Exception.Create('Error'+#13+#13+E.Message));
  finally
    Action := raAbort;
  end;

错误讯息:

  

错误

     

[FireDAC] [Phys] [ODBC] [Microsoft] [SQL Server Native Client 11.0] [SQL   Server] INSERT语句与FOREIGN KEY约束冲突   “FK_FIELD_FOREIGNKEY”。冲突发生在数据库中   “DBBALSAS_TESTE_PE”,表“dbo.TEST_TABLE_A”,列'FIEL。

我做了相同的插入,但是直接插入了FDQuery,错误已经完成:

  FDQuery1.SQL.Text := 'INSERT INTO TEST_TABLE_B(FIELD_FOREIGNKEY) VALUES(-1)';
  FDQuery1.ExecSQL;
  

[FireDAC] [Phys] [ODBC] [Microsoft] [SQL Server Native Client 11.0] [SQL   Server] INSERT语句与FOREIGN KEY约束冲突   “FK_FIELD_FOREIGNKEY”。冲突发生在数据库中   “DBBALSAS_TESTE_PE”,表“dbo.TEST_TABLE_A”,列   'FIELD_PRIMARYKEY'。

0 个答案:

没有答案