sc_change_connection working example

Hello,
this is a tip for beginners like me:
have you noticed how long does it take to process the code generations when you use a database on a remote server?

I finally replicated the db locally but had really an hard time in selecting the correct database every time.
Now my apps change db accordingly to where I am accessing them from.
It’s important that the application database is on your local machine to avoid taking too much to generate code;
it took me a while to achieve this and it might be helpful for others!

This has to be put in the onApplicationInit Event


$server = $_SERVER['SERVER_NAME'];

switch ($server) {
	case 'YOURDOMAINNAME':
		sc_change_connection ('conn_mysql_LCL', 'conn_mysql_WEB');
		break;
	case 'YOURLOCALSERVERNAME': //	or jus use default:
		break;
}

Have a good day!

Re: sc_change_connection working example

I try use the next command to change connection…

sc_change_connection (‘Actual’, ‘New_Connection’) ;

but Don’t work…
I Need another command later ? to activate this change ???

Hi Ramorales,

Please note when using sc_change_connection you need to redirect to another application to see the changes the first time.

[SIZE=4]Example using sc_change_connection [/SIZE]

Assuming that your connections are working properly and defined in Scrtipcase>Database>Add / Edit connection. Try something like this:

sc_change_connection("Old", "new") ;
sc_redir('destination');

Now all your applications are using the new connection. Example in Destination APP:

sc_lookup(ds, "sql command");

AND just this is not working, if the sc_redir point to a Control App !! The Control App ignores this changes.