Browse Source

* In case the initialization of odbc fails, do not raise exceptions while cleaning up

git-svn-id: trunk@15210 -
joost 15 years ago
parent
commit
819958228f
1 changed files with 11 additions and 5 deletions
  1. 11 5
      packages/fcl-db/src/sqldb/odbc/odbcconn.pas

+ 11 - 5
packages/fcl-db/src/sqldb/odbc/odbcconn.pas

@@ -1279,13 +1279,19 @@ var
   Res:SQLRETURN;
   Res:SQLRETURN;
 begin
 begin
   // free environment handle
   // free environment handle
-  Res:=SQLFreeHandle(SQL_HANDLE_ENV, FENVHandle);
-  if Res=SQL_ERROR then
-    ODBCCheckResult(Res,SQL_HANDLE_ENV, FENVHandle, 'Could not free ODBC Environment handle.');
+  if assigned(FENVHandle) then
+    begin
+    Res:=SQLFreeHandle(SQL_HANDLE_ENV, FENVHandle);
+    if Res=SQL_ERROR then
+      ODBCCheckResult(Res,SQL_HANDLE_ENV, FENVHandle, 'Could not free ODBC Environment handle.');
+    end;
 
 
   // free odbc if not used by any TODBCEnvironment object anymore
   // free odbc if not used by any TODBCEnvironment object anymore
-  Dec(ODBCLoadCount);
-  if ODBCLoadCount=0 then ReleaseOdbc;
+  if ODBCLoadCount>0 then
+    begin
+    Dec(ODBCLoadCount);
+    if ODBCLoadCount=0 then ReleaseOdbc;
+    end;
 end;
 end;
 
 
 { TODBCCursor }
 { TODBCCursor }