Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mixing of usersessions?
#1
Hi

I use a datamodule pool with my program. Each user can have a different db to look at. The usersession holds the path to that database,
Now i adjusted the Lock and Unlock :

Code:
function LockDataModule: TDtmMain;
begin
  Result := TDtmMain(TIWServerController(GServerController).Pool.Lock);
  if Result.IBDatabase.Connected then
  begin
    if Result.IBTransaction.InTransaction then
         Result.IBTransaction.Rollback;

    Result.IBDatabase.Connected := False;
  end;

  Result.IBDatabase.DatabaseName := UserSession.DbPad;
  Result.IBDatabase.Open;
end;

And

Code:
procedure UnlockDataModule(ADataModule: TDtmMain);
var
  LTemp: TDataModule;
begin
  LTemp := ADataModule;
  if TDtmMain(LTemp).IBTransaction.InTransaction then
     TDtmMain(LTemp).IBTransaction.Rollback;

  TDtmMain(LTemp).IBDatabase.CloseDataSets;
  TDtmMain(LTemp).IBDatabase.Close;
  TDtmMain(ADataModule).IBDatabase.DatabaseName := '';

  TIWServerController(GServerController).Pool.Unlock(LTemp);
end;


However, once in every 4-6 months we have a customer showing me data from another customers db! Which is ofcourse not what i want.
After loggin out/in the users gets the correct database info.

It's all about the line

Code:
  Result.IBDatabase.DatabaseName := UserSession.DbPad;

Which should work properly , if it choses someone else its usersession, this goes wrong.

Any idea what could go wrong ???

Eric
Reply
#2
1) If you are pooling you are recycling database connections and you certainly could be leaving open state between reuses.

2) Depending on your DB connectivity using the DB name may be invalid. Most connectivity components require explicit assigning by session instance when used in threads rather than by name.
Reply
#3
Hi

You say:

1) If you are pooling you are recycling database connections and you certainly could be leaving open state between reuses.

Answer:
All database actions are between a LockDataModule try..finally UnlockDataModule . 
So if you see my code this should really work fine. I always close the transactions/database before re-using

2) Depending on your DB connectivity using the DB name may be invalid. Most connectivity components require explicit assigning by session instance when used in threads rather than by name.

Anwer:
I use UserSession.DbPad, which contains the full file spec to my interbase database. I dont see this could  go wrong.


Strange is also that this happens only with the first form shown?
This form shows a list of data, if i select a records it goes to a detail form , for which the technique is re-used and i get a error that the record was not found. The reason for this is that the detail uses a different database!

 This all happens just once in 3-4 months 

So what is the best approach now?

Leave the pooling mechanisme? 

Eric
Reply
#4
You might try logging database open/close vs session start to compare.

Just a question: If you close/open the database when you attach to a pool module, is there any advantage of pooled vs having the data module in the usersession?

Dan
Reply
#5
Hi

When i started pooling looked the right way to go, later i noticed that this is not really an advantage as you describe.

I now disabled pooling, create the datamodule in my usersession, set the databasepath en  it just works fine,

Eric
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)