From 0028210b53061313ad250c9479e5f176a43a214d Mon Sep 17 00:00:00 2001 From: lacak Date: Wed, 29 Oct 2014 11:42:02 +0000 Subject: [PATCH] fcl-db: mssql: if stored procedure raises error with severity > 10 then db-library calls error handler, which sets DBErrorNo and DBErrorStr. So check them after execution of SQL and raise also error if they are set. +Cancel any pending results or other commands in batch to allow ROLLBACK. git-svn-id: trunk@28944 - --- packages/fcl-db/src/sqldb/mssql/mssqlconn.pp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/fcl-db/src/sqldb/mssql/mssqlconn.pp b/packages/fcl-db/src/sqldb/mssql/mssqlconn.pp index b1d1a8355d..7e73c9525d 100644 --- a/packages/fcl-db/src/sqldb/mssql/mssqlconn.pp +++ b/packages/fcl-db/src/sqldb/mssql/mssqlconn.pp @@ -208,6 +208,7 @@ begin DBErrorStr:=DBErrorStr+LineEnding+dberrstr; DBErrorNo :=dberr; Result :=INT_CANCEL; + // for server messages with severity greater than 10 error handler is also called end; function DBMsgHandler(dbproc: PDBPROCESS; msgno: DBINT; msgstate, severity:INT; msgtext, srvname, procname:PChar; line:DBUSMALLINT):INT; cdecl; @@ -295,13 +296,15 @@ end; function TMSSQLConnection.CheckError(const Ret: RETCODE): RETCODE; var E: EMSSQLDatabaseError; begin - if Ret=FAIL then + if (Ret=FAIL) or (DBErrorStr<>'') then begin if DBErrorStr = '' then case DBErrorNo of SYBEFCON: DBErrorStr:='SQL Server connection failed!'; end; E:=EMSSQLDatabaseError.CreateFmt('Error %d : %s'+LineEnding+'%s', [DBErrorNo, DBErrorStr, DBMsgStr], Self, DBErrorNo, ''); + // try clear all pending results to allow ROLLBACK and prevent error 10038 "Results pending" + if assigned(FDBProc) then dbcancel(FDBProc); DBErrorStr:=''; DBMsgStr:=''; raise E;