Recent

Author Topic: Firebird connection problem  (Read 3984 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Firebird connection problem
« on: May 27, 2015, 10:44:41 am »
Hello guys, I have the following problem. On Linux 32-bit'm creating a server with tcp synapse. Until everything is right. But my server has to work also with firebird here and use the TibConnection. Now if I run the code once no problem, but when rieseguo the code a second time to be in error.

I realized it must be linked to the CharSet TibConnection. Who explains to me how to solve? thanks

Code: [Select]
function TTCPEchoThrd.ApriConnessioneAlDB(var Conn: TIBConnection; var Tran: TSQLTransaction; MyHostName: string; MyDataBaseName: string; MyUserName: string; MyPassword: string; var MsgError: string): boolean;
var
   ret: boolean;
begin
       try
          try
            ret:=true;
            //Conn.CharSet:='disabled'; //non esiste, ma almeno mi evita l'errore che mi fa saltare il db
            Conn.HostName:=MyHostName;
            Conn.DatabaseName:=MyDataBaseName;
            Conn.UserName:=MyUserName;
            Conn.Password:=MyPassword;
            Conn.Transaction:=Tran;
            Conn.Open;
            Tran.Active:=true;
            //ho ottenuto la connessione al database
          finally
                 //codice da effettuare a fine procedura sia che va bene il codice sopra sia che il codice ha sollevato un'eccezzione
         end;
       except
             on E: Exception do
             begin
                MsgError:=E.Message;
                ret:=false;
             end;
       end;
       result:=ret;
end;
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Firebird connection problem
« Reply #1 on: May 27, 2015, 12:10:26 pm »
The strange thing is that if I run the code from the IDE I have no problem. If you launch it from the terminal / console goes wrong.

An unhandled exception occurred at $B65975F5 :
EAccessViolation : Access violation
  $B65975F5
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Firebird connection problem
« Reply #2 on: May 27, 2015, 12:56:21 pm »
I don't think we have enough code.

Does that "unhandled exception" occur in that piece of code? (you could do some logging to see if it's really there and on what line)

Where do you call ApriConnessioneAlDB and is Conn properly created? etc... etc...

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Firebird connection problem
« Reply #3 on: May 27, 2015, 02:27:04 pm »
I think the problem is there, why comment if the piece of code there is no problem. The problem is that it is gentle enough for a project and I can not copy and paste all.

If anything, if anyone is interested to help me make a support session on my pc
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Firebird connection problem
« Reply #4 on: May 27, 2015, 04:52:59 pm »
The strange thing is that if I run the code from the IDE I have no problem. If you launch it from the terminal / console goes wrong.

An unhandled exception occurred at $B65975F5 :
EAccessViolation : Access violation
  $B65975F5
1) how do you run the code from the IDE? (opening the connection with the same paramas does not execute the code).
2) are you sure that the Conn is created when that procedure is called?

Where is that object placed at design time is the container created in any way?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Firebird connection problem
« Reply #5 on: May 28, 2015, 01:22:58 pm »
Where the appeal procedure offending. As you can see you make the connection
Code: [Select]
function TTCPEchoThrd.UtenteAbilitato(NomeUtente: string; Id_Utente: string):boolean;
var
   Conn: TIBConnection;
   Tran: TSQLTransaction;
   Query: TSQLQuery;
   ErrMes: string;
   ret: boolean;
begin
       try
          try
             Conn:=TIBConnection.Create(nil);
             Tran:=TSQLTransaction.Create(nil);
             if (Self.ApriConnessioneAlDB(Conn,Tran,'127.0.0.1','/DB/db.fdb','user','pwd',ErrMes)=true) then
              begin
                   ret:=false;
                   Self.CredenzialiOK:=false;
                   Self.Log('                                CONNESSIONE AL DB EFFETTUATA');
                   Query:=TSQLQuery.Create(nil);
                   Query.DataBase:=Conn;
                   Query.SQL.Text:='select PATH from T_User WHERE ID=:Id and Nome=:User';
                   Query.Params.ParamByName('Id').AsInteger := StrToInt(Id_Utente);
                   Query.Params.ParamByName('User').AsString := NomeUtente;
                   Query.Open;
                   if not Query.EOF then
                   begin
                        Query.First;
                        Self.DataBaseDellUtenteRemoto:=Trim(Query.FieldByName('PATH').AsString);
                        if ((Length(Self.DataBaseDellUtenteRemoto)>0) and (FileExists(Self.DataBaseDellUtenteRemoto))) then
                        begin
                           ret:=true;
                           Self.CredenzialiOK:=true;
                        end;
                   end;
                   Query.Close;
                   Query.Free;
                   Self.ChiudiConnessioneAlDB(Conn,Tran,ErrMes);
                   Self.Log('                                CONNESSIONE AL DB CHIUSA');
              end
              else
              begin
                   Self.Log('ERRORE ' + ErrMes);
              end;
          finally
                 //codice da effettuare a fine procedura sia che va bene il codice sopra sia che il codice ha sollevato un'eccezzione
            Tran.Free;
            Conn.Free;
         end;
       except
             on E: Exception do
             begin
                ret:=false;
                Self.Log('ERRORE ' + E.Message);
             end;
       end;
       result:=ret;
end;

Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018