Page 1 of 1

Slow app

Posted: Wed 17 Apr 2013 17:03
by markdelphi
Hello

I'm working with the SDAC components, but after a while my application running computer becomes very very slow to the point that no longer responds. I check my connections to the SQL Profile and seems fine. I have a class that is TConexion I use to connect not know if I'm doing something wrong. I send the class to see if it is good and an example of its use.

Code: Select all

unit UntConexion;

interface

 Uses MSAccess,ADODB,DB;

type

 TConexion = class
  private
   FError : string;
   FCadenaConexion : string;
   FConexion : TMSConnection;
   FStoredProc : TMSStoredProc;
   FMuestraVentanaConexion : Boolean;
   function GetCadenaConexion : string;
   procedure WriteCadenaConexion(AValue : string);
  public
   constructor Create;
   destructor Destroy;override;
   function Abrir : Boolean;
   procedure Cerrar;
   property CadenaConexion : string read GetCadenaConexion write WriteCadenaConexion;
   property Error : string read FError write FError;
   property MuestraVentanaConexion : Boolean read FMuestraVentanaConexion write FMuestraVentanaConexion;
   property StoreProcedure : TMSStoredProc read FStoredProc;
   property Conexion : TMSConnection read FConexion;
 end;

implementation

uses untClasesBasicas, UntCfgBD,Forms,Controls,SysUtils,Classes,OLEDBAccess;


{ TConexion }



procedure TConexion.Cerrar;
begin
 FConexion.Close;
end;

constructor TConexion.Create;
begin
 FConexion := TMSConnection.Create(Nil);
 FConexion.LoginPrompt := False;
 FConexion.Options.DisconnectedMode := True;
 FConexion.Pooling := True;
 FConexion.Authentication := auWindows;
 FConexion.Options.Provider := prNativeClient;
 FConexion.Options.NativeClientVersion := nc2012;
 FStoredProc := TMSStoredProc.Create(Nil);
 FStoredProc.Connection := FConexion;
 FMuestraVentanaConexion := True;
end;


destructor TConexion.Destroy;
begin
 FStoredProc.Free;
 FConexion.Free;
 inherited Destroy;
end;

procedure TConexion.WriteCadenaConexion(AValue: string);
begin
 OpcionesRegistro.CadenaConexion :=  AValue;
end;


function TConexion.GetCadenaConexion : string;
var
 Enc : TEnc;
begin
 Enc := TEnc.Create;
 try
  FCadenaConexion := OpcionesRegistro.CadenaConexion;
  Enc.TextoEnc := FCadenaConexion;
  Enc.DesEnc;
  Result := Enc.Texto;
 finally
  Enc.Free;
 end;
end;


function TConexion.Abrir : Boolean;
var
 cnxString : string;
 Enc : TEnc;
begin
 try
  FConexion.ConnectString := CadenaConexion;
  FConexion.Open;
  Result := True;
 except
  on ex : Exception do
   begin
    if FMuestraVentanaConexion then
     begin
      if frmCfgBD.MuestraCfgBD(cnxString) then
       begin
        Enc := TEnc.Create;
        try
         Enc.Texto := cnxString;
         Enc.Enc;
         WriteCadenaConexion(Enc.TextoEnc);
         Result := True;
        finally
         Enc.Free;
        end;
       end
      else
       begin
        Result := False;
        FError := 'No se ha podido establecer conexión a la base de datos.' + #13#13 + 'La acción ha sido cancelada por el usuario.'
       end;
     end
    else
     begin
      FError := 'Ha ocurrido un error al intentar conectar a la base de datos ' + #13#10 + ex.Message;
      Result := False;
     end;
   end;
 end;
end;
end.
And an example of its use

Code: Select all

function TMovInv.Guardar : Boolean;
var
 Conexion : TConexion;
begin
 Result := true;
 Conexion := TConexion.Create;
 Conexion.Abrir;
 try
  Conexion.StoreProcedure.Close;
  Conexion.StoreProcedure.StoredProcName := 'PA_OPERACIONES_MOVINV';
  Conexion.StoreProcedure.Params.ParamByName('PMENU').Value := 'tsrInserta';
  Conexion.StoreProcedure.Params.ParamByName('DATOS').Value := Get_XML;
  Conexion.StoreProcedure.ExecProc;
  if Conexion.StoreProcedure.Params.ParamByName('PMensaje').Value <> 'SIN ERROR' then
   begin
    Error := Conexion.StoreProcedure.Params.ParamByName('PMensaje').Value;
    Result := false;
   end
 finally
  Conexion.Free;
 end;
end;

Re: Slow app

Posted: Thu 18 Apr 2013 09:17
by AndreyZ
Hello,

Please try creating a small sample to demonstrate the problem and send it to andreyz*devart*com , including the script to create all needed server objects (tables, stored procedures, etc.). Also please specify the following:
- the exact version of SDAC. You can learn it from the About sheet of TMSConnection Editor;
- the exact version of your IDE;
- the exact version of SQL Server server and client you are using. You can learn it from the Info sheet of TMSConnection Editor.