Board index » delphi » Session.ModifyAlias question

Session.ModifyAlias question

Hi,

I have a program with a large number of Tables and Querys.

I want the user to be able to work with LiveData, or TestData.

I cannot use a second alias for TestData, because I would
have to change too many Tables and Querys.

The Session has a method 'ModifyAlias' that changes the path of
an alias.

The following code will change the path of my alias (Tbs)

procedure TForm1.TestDataBtnClick(Sender: TObject);
var   List: TStringList;
begin
  List := TStringList.Create;
  List.Clear;
  List.Add('PATH=\DB\TestData');

  Session.ModifyAlias('Tbs', List);
  List.Free;
  Session.Active:=False;
  Session.Active:=True;

  Table1.Open; // Open All Tables
end;
---------

The above procedure works, sometimes.
It only works, if I am in the IDE, and change Table1's
alias to another alias and then back to 'Tbs'.

If I try and run the program without changing Table1's
alias first, nothing happens.

What am I doing wrong?
How do I get Session.ModifyAlias to work all the time?
Is there some other property of Session that I must set first?
I can't find any help, in Delphi's help.

Thanks,

Frank
-------------

 

Re:Session.ModifyAlias question


Hi,

I have another strategy taht works for me in a similar situation. All my
tables are connected to a single TDatabase coponent.

When i need to change the server name, i take the database params and change
the SERVER NAME entry in it (after closing the database) and then reopens
it...

It changes the path of the tables when i reopen it.

Never tried this with TSessions though..

hope this helps

Salim

Quote
Frank Fortino wrote in message <3731BCA8.7A56A...@svn.net>...
>Hi,

>I have a program with a large number of Tables and Querys.

>I want the user to be able to work with LiveData, or TestData.

>I cannot use a second alias for TestData, because I would
>have to change too many Tables and Querys.

>The Session has a method 'ModifyAlias' that changes the path of
>an alias.

>The following code will change the path of my alias (Tbs)

>procedure TForm1.TestDataBtnClick(Sender: TObject);
>var   List: TStringList;
>begin
>  List := TStringList.Create;
>  List.Clear;
>  List.Add('PATH=\DB\TestData');

>  Session.ModifyAlias('Tbs', List);
>  List.Free;
>  Session.Active:=False;
>  Session.Active:=True;

>  Table1.Open; // Open All Tables
>end;
>---------

>The above procedure works, sometimes.
>It only works, if I am in the IDE, and change Table1's
>alias to another alias and then back to 'Tbs'.

>If I try and run the program without changing Table1's
>alias first, nothing happens.

>What am I doing wrong?
>How do I get Session.ModifyAlias to work all the time?
>Is there some other property of Session that I must set first?
>I can't find any help, in Delphi's help.

>Thanks,

>Frank
>-------------

Re:Session.ModifyAlias question


Quote
In article <3731BCA8.7A56A...@svn.net>, Frank Fortino wrote:
> procedure TForm1.TestDataBtnClick(Sender: TObject);
> var   List: TStringList;
> begin
>   List := TStringList.Create;
>   List.Clear;
>   List.Add('PATH=\DB\TestData');

>   Session.ModifyAlias('Tbs', List);
>   List.Free;
>   Session.Active:=False;
>   Session.Active:=True;

>   Table1.Open; // Open All Tables
> end;

Your problem may be caused by table(s) being open when you issue
ModifyAlias (note that Session.Active:=False follows it).

I would re-write your routine as:

 var   List: TStringList;
 begin
   List := TStringList.Create;
   try
     List.Add('PATH=\DB\TestData');

     Session.Active:=False;
     Session.ModifyAlias('Tbs', List);
     Session.Active:=True;  

     Table1.Open; // Open All Tables
   finally
     List.Free;
   end;
 end;

 Mike Orriss (TeamB)
 (No e-mail replies, please, unless explicitly requested!)

Re:Session.ModifyAlias question


Another solution is to use a TDatabase component. Then you can have an alias
for your test data and an alias for the live data. To switch between them
do:

with Database1 do
begin
  Connected := False;
  AliasName := 'NewAlias';
  Connected := True;
end;

You will have to reopen your tables after executing this code.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to email questions. To contact me
 for any other reason remove nospam from my address.)

Other Threads