mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-14 03:19:27 +02:00
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:
parent
f432d4c0c6
commit
0028210b53
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user