Servidor: al adquirir conexiones de BD comprobar si hay conexión antes de utilizarlas en los servicios.
git-svn-id: https://192.168.0.254/svn/Proyectos.LuisLeon_FactuGES/trunk@269 c93665c3-c93d-084d-9b98-7d5f4a9c3376
This commit is contained in:
parent
a501958189
commit
f146ff560d
@ -87,7 +87,7 @@ procedure TsrvTiendaWeb.bp_osc_CustomersGenerateSQL(
|
|||||||
const ReferencedStatement: TDAStatement; const aDelta: IDADelta;
|
const ReferencedStatement: TDAStatement; const aDelta: IDADelta;
|
||||||
var SQL: string);
|
var SQL: string);
|
||||||
begin
|
begin
|
||||||
dmServer.EscribirLog(SQL + #10#13 + #10#13);
|
dmServer.EscribirLog(SQL + #13#10 + #13#10);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsrvTiendaWeb.DARemoteServiceBeforeGetDatasetData(
|
procedure TsrvTiendaWeb.DARemoteServiceBeforeGetDatasetData(
|
||||||
|
|||||||
@ -41,8 +41,11 @@ object dmServer: TdmServer
|
|||||||
end
|
end
|
||||||
object ConnectionManager: TDAConnectionManager
|
object ConnectionManager: TDAConnectionManager
|
||||||
MaxPoolSize = 10
|
MaxPoolSize = 10
|
||||||
PoolTimeoutSeconds = 60
|
PoolTimeoutSeconds = 120
|
||||||
PoolBehaviour = pbWait
|
PoolBehaviour = pbWait
|
||||||
|
OnConnectionAcquired = ConnectionManagerConnectionAcquired
|
||||||
|
OnConnectionTimedOut = ConnectionManagerConnectionTimedOut
|
||||||
|
OnConnectionCreated = ConnectionManagerConnectionCreated
|
||||||
WaitIntervalSeconds = 1
|
WaitIntervalSeconds = 1
|
||||||
Connections = <
|
Connections = <
|
||||||
item
|
item
|
||||||
@ -96,4 +99,13 @@ object dmServer: TdmServer
|
|||||||
Left = 232
|
Left = 232
|
||||||
Top = 136
|
Top = 136
|
||||||
end
|
end
|
||||||
|
object ADOQuery1: TADOQuery
|
||||||
|
Parameters = <>
|
||||||
|
Left = 320
|
||||||
|
Top = 224
|
||||||
|
end
|
||||||
|
object ADOConnection1: TADOConnection
|
||||||
|
Left = 248
|
||||||
|
Top = 208
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,7 +8,8 @@ uses
|
|||||||
uROSessions, uDADataTable, uDABINAdapter, IBSQLMonitor, JvComponent,
|
uROSessions, uDADataTable, uDABINAdapter, IBSQLMonitor, JvComponent,
|
||||||
JvAppStorage, JvAppRegistryStorage, uDAInterfaces,
|
JvAppStorage, JvAppRegistryStorage, uDAInterfaces,
|
||||||
JvComponentBase, uROEventRepository,
|
JvComponentBase, uROEventRepository,
|
||||||
SyncObjs, JvLogFile, uDAIBXDriver, uDAADODriver;
|
SyncObjs, JvLogFile, uDAIBXDriver, uDAADODriver, DB, IBCustomDataSet, IBQuery,
|
||||||
|
ADODB;
|
||||||
|
|
||||||
const
|
const
|
||||||
SERVER_PORT = '8099'; // Puerto por defecto
|
SERVER_PORT = '8099'; // Puerto por defecto
|
||||||
@ -27,6 +28,8 @@ type
|
|||||||
DAIBXDriver: TDAIBXDriver;
|
DAIBXDriver: TDAIBXDriver;
|
||||||
DAADODriver: TDAADODriver;
|
DAADODriver: TDAADODriver;
|
||||||
ConnectionManager: TDAConnectionManager;
|
ConnectionManager: TDAConnectionManager;
|
||||||
|
ADOQuery1: TADOQuery;
|
||||||
|
ADOConnection1: TADOConnection;
|
||||||
procedure DataModuleCreate(Sender: TObject);
|
procedure DataModuleCreate(Sender: TObject);
|
||||||
procedure DataModuleDestroy(Sender: TObject);
|
procedure DataModuleDestroy(Sender: TObject);
|
||||||
procedure HTTPServerBeforeServerActivate(Sender: TObject);
|
procedure HTTPServerBeforeServerActivate(Sender: TObject);
|
||||||
@ -34,6 +37,11 @@ type
|
|||||||
Tag: Integer);
|
Tag: Integer);
|
||||||
procedure SessionManagerSessionDeleted(const aSessionID: TGUID;
|
procedure SessionManagerSessionDeleted(const aSessionID: TGUID;
|
||||||
IsExpired: Boolean);
|
IsExpired: Boolean);
|
||||||
|
procedure ConnectionManagerConnectionAcquired(Sender: TDAConnectionManager;
|
||||||
|
const Connection: IDAConnection);
|
||||||
|
procedure ConnectionManagerConnectionTimedOut(Sender: TDAConnectionManager);
|
||||||
|
procedure ConnectionManagerConnectionCreated(Sender: TDAConnectionManager;
|
||||||
|
const Connection: IDAConnection);
|
||||||
private
|
private
|
||||||
FEscribirLog : TCriticalSection;
|
FEscribirLog : TCriticalSection;
|
||||||
FConnectionName : string;
|
FConnectionName : string;
|
||||||
@ -65,6 +73,8 @@ function Encrypt (const Source : string) : String;
|
|||||||
function Decrypt (const Source : string) : String;
|
function Decrypt (const Source : string) : String;
|
||||||
function GetNextAutoinc(AConnection : IDAConnection; const GeneratorName: string): integer;
|
function GetNextAutoinc(AConnection : IDAConnection; const GeneratorName: string): integer;
|
||||||
|
|
||||||
|
procedure CheckConnection(AConnection: IDAConnection);
|
||||||
|
|
||||||
var
|
var
|
||||||
dmServer: TdmServer;
|
dmServer: TdmServer;
|
||||||
|
|
||||||
@ -76,6 +86,55 @@ uses
|
|||||||
DateUtils, JclFileUtils, ActiveX, Forms, Registry, Windows, Dialogs,
|
DateUtils, JclFileUtils, ActiveX, Forms, Registry, Windows, Dialogs,
|
||||||
uSesionesUtils, uServerAppUtils;
|
uSesionesUtils, uServerAppUtils;
|
||||||
|
|
||||||
|
|
||||||
|
procedure CheckConnection(AConnection: IDAConnection);
|
||||||
|
var
|
||||||
|
AIBXQuery : TIBQuery;
|
||||||
|
AADOQuery : TADOQuery;
|
||||||
|
begin
|
||||||
|
if ((AConnection as IDAConnectionObjectAccess ).ConnectionObject is TIBXConnection) then
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
AIBXQuery := TIBQuery.Create(NIL);
|
||||||
|
try
|
||||||
|
AIBXQuery.SQL.Add('select distinct 1 from RDB$TRANSACTIONS');
|
||||||
|
AIBXQuery.Database := ((AConnection as IDAConnectionObjectAccess ).ConnectionObject as TIBXConnection).Database;
|
||||||
|
AIBXQuery.Open;
|
||||||
|
finally
|
||||||
|
FreeANDNIL(AIBXQuery);
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on E:Exception do
|
||||||
|
begin
|
||||||
|
AConnection.Close;
|
||||||
|
AConnection.Open;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
if ((AConnection as IDAConnectionObjectAccess ).ConnectionObject is TADOConnection) then
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
AADOQuery := TADOQuery.Create(NIL);
|
||||||
|
try
|
||||||
|
AADOQuery.SQL.Add('select count(*) From master.dbo.sysdatabases');
|
||||||
|
AADOQuery.Connection := ((AConnection as IDAConnectionObjectAccess ).ConnectionObject as TADOConnection);
|
||||||
|
AADOQuery.Open;
|
||||||
|
finally
|
||||||
|
FreeANDNIL(AADOQuery);
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on E:Exception do
|
||||||
|
begin
|
||||||
|
AConnection.Close;
|
||||||
|
AConnection.Open;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function DarRutaInformes : String;
|
function DarRutaInformes : String;
|
||||||
begin
|
begin
|
||||||
Result := ExtractFilePath(Application.ExeName) + 'Informes' + PathDelim;
|
Result := ExtractFilePath(Application.ExeName) + 'Informes' + PathDelim;
|
||||||
@ -145,6 +204,24 @@ begin
|
|||||||
Result := Result + chr(ord(Source[i]) - Random(10) - 1);
|
Result := Result + chr(ord(Source[i]) - Random(10) - 1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TdmServer.ConnectionManagerConnectionAcquired(
|
||||||
|
Sender: TDAConnectionManager; const Connection: IDAConnection);
|
||||||
|
begin
|
||||||
|
EscribirLog('Conexión adquirida: ' + Connection.Name + #13#10 + #13#10);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TdmServer.ConnectionManagerConnectionCreated(
|
||||||
|
Sender: TDAConnectionManager; const Connection: IDAConnection);
|
||||||
|
begin
|
||||||
|
EscribirLog('Conexión creada: ' + Connection.Name + #13#10 + #13#10);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TdmServer.ConnectionManagerConnectionTimedOut(
|
||||||
|
Sender: TDAConnectionManager);
|
||||||
|
begin
|
||||||
|
EscribirLog('Error de timeout en conexión' + #13#10 + #13#10);
|
||||||
|
end;
|
||||||
|
|
||||||
function TdmServer.DarNuevaConexion: IDAConnection;
|
function TdmServer.DarNuevaConexion: IDAConnection;
|
||||||
begin
|
begin
|
||||||
with ConnectionManager do
|
with ConnectionManager do
|
||||||
@ -233,8 +310,9 @@ end;
|
|||||||
|
|
||||||
procedure TdmServer.DataModuleDestroy(Sender: TObject);
|
procedure TdmServer.DataModuleDestroy(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
SessionManager.ClearSessions(False);
|
|
||||||
HTTPServer.Active := False;
|
HTTPServer.Active := False;
|
||||||
|
SessionManager.ClearSessions(False);
|
||||||
|
ConnectionManager.ClearPool;
|
||||||
DetenerLog;
|
DetenerLog;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -246,7 +324,7 @@ end;
|
|||||||
procedure TdmServer.DriverManagerTraceEvent(Sender: TObject; const Text: string;
|
procedure TdmServer.DriverManagerTraceEvent(Sender: TObject; const Text: string;
|
||||||
Tag: Integer);
|
Tag: Integer);
|
||||||
begin
|
begin
|
||||||
EscribirLog(Text + #10#13 + #10#13);
|
EscribirLog(Text + #13#10 + #13#10);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TdmServer.EscribirLog(const AMensaje: String);
|
procedure TdmServer.EscribirLog(const AMensaje: String);
|
||||||
|
|||||||
Reference in New Issue
Block a user