Browse Source

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 -
lacak 10 years ago
parent
commit
0028210b53
1 changed files with 4 additions and 1 deletions
  1. 4 1
      packages/fcl-db/src/sqldb/mssql/mssqlconn.pp

+ 4 - 1
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;