PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Ajuda para melhorar o código de conexão com o banco #574005

19/01/2017

0

Bom dia, gostaria da ajuda dos amigos para melhorar o código.

function TDtMdl.Conecta_Banco() : boolean;
var pathexe,host, txt: String;
begin
    result := true;
    pathexe := ExtractFilePath (Application.ExeName);
    Try
        FB_DataBase.Connected := false;
        FB_DriverLink.VendorLib := Ler_chave_reg ('Default', 'PathLibrary', GetDOSEnvVar ( 'PROGRAMFILES' ) + 'C:\\Program Files\\Firebird\\Firebird_3_0\\fbclient.dll', g_nome_ini);
        Grava_chave_reg ('Default', 'PathLibrary', FB_DriverLink.VendorLib, g_nome_ini);
        host := Ler_chave_reg ('Default', 'Ident_Host', '', g_nome_ini);
        FB_DataBase.Params.Values['server'] := host;
        Grava_chave_reg ('Default', 'Ident_Host', host, g_nome_ini);

        if (UpperCase(host) <> 'LOCALHOST') then
        begin
            IdIcmpClient.Host := host;
            if IdIcmpClient.ReplyStatus.BytesReceived = 0 then
                raise Exception.create('Servidor não localizado !'+#13+#13+'Verifique as configurações de conexão !');
        end
        else
        begin
            FB_DataBase.Params.Values['database'] := Ler_chave_reg ('Default', 'PathDados', '', g_nome_ini);
            FB_DataBase.Connected := True;
        end;
    Except
        on E:Exception do
        begin
            txt := FORMAT('%s%s'#13'%s%d',['Mensagem do FireDac: '+#13+#13,E.message+#13,'Codigo de Error do FD : ', E.HelpContext]);
            Application.messagebox ( pchar(txt) ,'Aviso!',MB_OK + MB_ICONERROR);
            result := false;
        end;
    end;
    if (not abreTabelas)  Then
    begin
        result := false;
        Application.Terminate;
    end;
end;
Emanuel Gonçalves

Emanuel Gonçalves

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar