NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: Mike J on June 21, 2007, 06:32:34 AM

Title: Session Variable Question
Post by: Mike J on June 21, 2007, 06:32:34 AM
Can a dictionary table's connection string be based on a session variable? I currently have a window's app where the dictionary tables' connection strings are based on global variables since they reside on different DBs. The first level connection string can be hard coded into the web app, but the other levels' connection strings reside in a table and retrieved based on how the user logs in. I would like to use this same approach, but instead of using global variables in the dictionary I would like to use session variables.
Title: Re: Session Variable Question
Post by: Gregg Matteson on June 21, 2007, 07:21:36 AM
Mike,

I have not tried this but...

could you put the connection string in a file (tps?) then in the validate imbed of the login form set the tps file and retrieve the correct connection string from the appropriate record. Maybe no session variable needed?

Regards,

Gregg Matteson
Title: Re: Session Variable Question
Post by: ChrisLaurie on June 21, 2007, 07:22:12 AM
Hi Mike

AFAIK a session variable can store anything you want - it holds it value relative to the sessions connection.

I have a table called datasets where I store paths (relevant to the sserver). In my login the user must specify the dataset code. In my login form procedure I then look up the dataset and call a SyncDataset procedure that sets the {Prop:Name} of all the relevant tables. It also tries to oepn them and logs errors as well as set a session value and returns the error. If successful it stores the id of the dataset in a session variable the login goes through.

Then in the WebHandler procedure I get the DatasetId session variable and call the SyncDataset procedure and that resets the name for the current request.

I have also successfully parsed the incoming url for the dataset code and worked from there. This however requires some dns magic to make work:
dataset.domain.com

Cheers

Chris
Title: Re: Session Variable Question
Post by: Bruce on June 21, 2007, 08:41:31 AM
Hi Mike,

The embed point to use, to set the connection string for tables, is in the WebHandler procedure.

Use the .ProcessLink method, before the "parent" call.

Typically at this point you'll want to check a Session Variable (usually set when the user logs in) to determine what the connection string should be.

Cheers
Bruce
Title: Re: Session Variable Question
Post by: Mike J on June 21, 2007, 10:03:07 AM
Thanks for the suggestions! I got pulled off of it for a few days, but one of the ideas I'm sure will work. It's nice to have some extra brains to use  :)
Title: Re: Session Variable Question
Post by: Alan Cochran on June 22, 2007, 10:31:03 AM
Chris,

Do you have sample code that you can send me on how this is done?

Thanks...
Alan
Title: Re: Session Variable Question
Post by: Alan Cochran on June 25, 2007, 08:23:25 AM
All,

Since using a global variable in the dictionary for File Names doesn't work in the NetTalk web environment (ie !GLO:FileName_CUS), what should I put in the dictionary to handle changing to a different dataset?

TIA,
Alan
Title: Re: Session Variable Question
Post by: Bruce on June 26, 2007, 12:59:38 AM
Hi Alan,

As long as the variables are THREADED you can use them. Because basically that means that at the start of each thread they are set, and exist (and are "local") for the life of that thread.

So (a) make sure they're threaded.

Then (b)

In WebHandler procedure
.ProcessLink method
Before parent call


GLO:FileName_CUS = p_web.GetSessionValue('userpath') & '\Customer'

Where "userpath" is something you set when the user originally logged in.

cheers
Bruce
Title: Re: Session Variable Question
Post by: kevin plummer on June 27, 2007, 01:05:57 AM
Bruce from what you said here, does this also apply to MSSQL? Do I have to issue any prop:sql Use data base etc?

Cheers,

Kevin
Title: Re: Session Variable Question
Post by: Bruce on June 27, 2007, 11:28:26 PM
Hi Kevin,

I'm not the SQL expert, so any others that want to comment, please feel free.

The short answer is that, for SQL, you'd set the "owner" string for each table in the same place.

As I understand it, Clarion doesn't like being connected to 2 different databases at the same time. But I'm a little fuzzy on this bit.
If that is the case then I would suggest using variable table names, and so keeping the data all in one "database" but in separate "tables".

cheers
Bruce


Title: Re: Session Variable Question
Post by: kevin plummer on June 28, 2007, 01:42:30 AM
Thanks Bruce, 1 database is not an option as the data is already in separate databases. I have written a program that runs through and checks multiple sql databases so I think I had to disconnect and reconnect. I'll give it a go. If not I will just run multiple web server programs unless you think that is a bad idea.

Kev