If you have a project where you want to change the database in accordance with the logged user, first you should create the database connections in the project. So you must use the “sc_change_connection”(http://downloads.scriptcase.net/downloads/v5/manual/en_us/webhelp/manual_mp/80-Apendice/08-Programacao/01-Macro_sc/00-macros_sc.htm#sc_change_connection) macro to swap the connection.
for example:
databases
dbcompany_x
dbcompany_y
dbcompany_z
dbdefault contain the user and security tables
Create these connections in the project.
Now in the login form we must use the onValidate event to get the company of the user.
If the login form has the fields: “user”, “password” and “company” (select field).
So we can use:
$i = {company};
switch ($i) {
case ‘company_x’:
sc_change_connection(‘dbdefault’,‘dbcompany_x’);
break;
case ‘company_y’:
sc_change_connection(‘dbdefault’,'dbcompany_y);
break;
case ‘company_z’:
sc_change_connection(‘dbdefault’,‘dbcompany_z’);
break;
}
If you don’t have the “company” field in the login form, so you should use “sc_lookup”(http://downloads.scriptcase.net/downloads/v5/manual/en_us/webhelp/manual_mp/80-Apendice/08-Programacao/01-Macro_sc/00-macros_sc.htm#sc_lookup) to get the company of that user.
V?tor Jamil