CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

problem with sessions and change database

by hsbelli72 » 27 Jul 2017 17:00

hi, i have this situation.. i need my iwapp change the database when start depending of parameter. for exmaple

one pc use this url
http://192.168.1.35:9092/$/start?Param1=2 -> start with database locate in c:\xx\xx.gdb

second pc use this url
http://192.168.1.35:9092/$/start?Param1=1 -> start with database locate in c:\xx\prueba\xx.gdb

the problem is when use the url in second pc dont change database use the same database in url of one pc. use the same iw sessions


use this code in event IWServerControllerBaseNewSession
================================================

ASession.Data := TArchivos.Create(nil);

UserSession.nombreusuario := '';

MyIniFile := TIniFile.Create(gsAppPath + 'DbBapsGesWebLite.ini');

if ASession.RunParams.Values['Param1'] <> '' then
begin
mbase := MyIniFile.ReadString('BASES', 'BASE' + ASession.RunParams.Values
['Param1'], '');

end
else
begin
mbase := MyIniFile.ReadString('BASES', 'BASE' + inttostr(1), '');

end;

// mbase := MyIniFile.ReadString('BASES', 'BASE' + IntToStr(1), '');

posi := pos('-', mbase);
laruta := copy(mbase, posi + 1, length(mbase));
labase := copy(mbase, 1, posi - 1);
UserSession.basedatos := laruta;
if UserSession.SDDatabase1.Connected then
UserSession.SDDatabase1.Connected := false;
UserSession.SDDatabase1.params.Clear;

UserSession.SDDatabase1.FormatOptions.OwnMapRules := True;
UserSession.SDDatabase1.FormatOptions.MapRules.Add(dtSingle, dtDouble);
UserSession.SDDatabase1.params.Add('User_Name=sysdba');
UserSession.SDDatabase1.params.Add('Password=masterkey');
UserSession.SDDatabase1.params.Add('SQLDialect=1');
UserSession.SDDatabase1.params.Add('CharacterSet=ISO8859_1');
// UTF8 ISO8859_1
UserSession.SDDatabase1.params.Add('UseUnicode=False');
UserSession.SDDatabase1.params.Add('LongStrings=False');
UserSession.SDDatabase1.params.Add('UseQuoteChar=False');

UserSession.SDDatabase1.params.Add('TrimFixedChar=False');
UserSession.SDDatabase1.params.Add('ExtendedMetadata=false');
UserSession.SDDatabase1.params.Add('DriverID=FB');
UserSession.SDDatabase1.params.Add('Database=' + UserSession.basedatos);
UserSession.SDDatabase1.Connected := True;

please can helpme..

regards
hsbelli72
 
Posts: 296
Joined: 14 Mar 2013 18:10

by zsleo » 27 Jul 2017 20:53

Hi,
I use MS SQL and implement user based database assignment too.

The main difference between what you are doing and what I do is in ServerController I set a variable
In UserSession an do all the database connection assignment and connect from UserSession and not ServerController.

It is many years since I solved this issue but I think I had the same problem as you.

Regards
zsleo
 
Posts: 737
Joined: 03 Feb 2013 03:33

by zsleo » 27 Jul 2017 21:03

.... also, thanks to Alexandre Machado (IntraWeb), there is a VERY important thing you MUST do for every dataset component in your application connect to that database. You MUST manually assign it's database connection at run time before use. I do it in BeforeCoonect.

If you don't then you will have data "bleeding" between user sessions.

Good luck...
zsleo
 
Posts: 737
Joined: 03 Feb 2013 03:33

by hsbelli72 » 27 Jul 2017 22:27

hi zsleo, thank you for yours tips.. i try do this in my application.. you have any example for review?..

regards
hernan
hsbelli72
 
Posts: 296
Joined: 14 Mar 2013 18:10

by zsleo » 28 Jul 2017 00:05

Hi,

In UserSession I assign some public variables with source values from the browser parameters.

I then use these to assign my TADOConnection settings. In my application this is sourced from a master database.

For every dataset component I have:
Code: Select all
procedure TiwcgjqfrmMCAClaims.DataSetBeforeOpen(DataSet: TDataSet);
begin
  {conSite is my per-user database}
  if (DataSet as TADOQuery).Connection <> UserSession.conSite then
    (DataSet as TADOQuery).Connection := UserSession.conSite;

end;


I hope the following helps.
zsleo
 
Posts: 737
Joined: 03 Feb 2013 03:33

by hsbelli72 » 28 Jul 2017 16:52

hi zsleo, i modify every event beforeopen of tdataset of all my app and run ok.. thank you.. save mi life with yours tips.

regards
hernan
hsbelli72
 
Posts: 296
Joined: 14 Mar 2013 18:10

by zsleo » 28 Jul 2017 20:00

My pleasure- care of Alexandre Machado who gave me the fix to begin with.
zsleo
 
Posts: 737
Joined: 03 Feb 2013 03:33


Return to General

cron

Who is online

Users browsing this forum: No registered users and 173 guests

Contact Us.