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 -
This commit is contained in:
lacak 2014-10-29 11:42:02 +00:00
parent f432d4c0c6
commit 0028210b53

View File

@ -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;