sc_connection_edit and new name can be variable

I am writing system that will centralize control for number of distributed systems and this means I need to write applications with constantly changing connections based on system i am looking at.

When working with" sc_connection_edit" and “sc_connection_new” functions I found that name of the connection can not be a variable, if it is you get php error.

It must be possible to create dynamic names for connections and also send dynamic names for sql_execute and other sql commands.

For example this works as intended
sc_connection_edit(“db_connection”, $arr_conn);

However this example throws php error that ; is missing
sc_connection_edit("$db_connection", $arr_conn);

Not sure if it would work but try to use a global. Like

[myconnection]=…
sc_connection_edit([myconnection], $arr_conn);

sc_connection_edit is a sc macro and is interpreted before php does afaik.

Hey, i did that golbals [var] and sc vars format {var} it does not work.

Also there seems to be a bug with connection update logic, when you change connection in an event and run the app, it does not use new update connection and instead pull cashed connection data. Once you refresh the page it then has updated connection info on your previous run and then connection with info you want.

I am using the connection info change function in OnScriptInit and it does not get updates for the grid content.

So lets say i have DB Server A and B

If I open grid and send server A id I want it to dynamically update connection info for the grid and pull records for DB server A.
Since I am changing same connection application is using, before records even begin pulling I expect that this would work.

What happens is when I run the application, And send server id A - everything is good and server A data is pulled but if I then send server B then I still see server A data in the the grid, but if i refresh it - it is now connection B. So update to connection happens after application runs not before records are pulled.

So although connection should have changed, before grid began pulling records - it uses stored info and updates it after. This defeats the whole reason why i used connection change, I want to dynamically swap connection so system processes grid on different database.

Additionally I need connection change to be available for onRecord actions because as i list servers I want to go to each one separately and do data analytics and display relevant results in the grid row. I do not think this is even implemented.

I updated scriptcase v9 to latest version and connection edit stopped working altogether

I create grip application and OnScriptInit even I put following code

$arr_conn = array();

$arr_conn[‘drive’] = “pdo_mysql”;
$arr_conn[‘server’] = “10.1.1.180”;
$arr_conn[‘user’] = “user”;
$arr_conn[‘password’] = “pass”;
$arr_conn[‘database’] = “test_table”;
$arr_conn[‘persistent’] = “Y”;
$arr_conn[‘encoding’] = “utf8”;

sc_connection_new(“target_server”, $arr_conn);

This is supposed to create new connection called target_server and I should be able to use it immediately after Like this

sc_lookup(Dataset, “SELECT * FROM test_table”, “target_server”);

{row} = {Dataset}[0][0];

But requesting target_server connection throws following error before application even compiles
[SIZE=12px](sc_lookup => target_server) : This application requires a connection to be performed. The connection is still not set.[/SIZE]
[SIZE=12px]To change it please go the [/SIZE]SQL option in the left menu, and edit the Connection

This code works on version 8 and worked with bugs but on version 9 but in latest update it died.
Please fix these issues, my current project depends on ability to dynamically change connections.
i need to be able to change grids main connection info before grid loads any data from database so i can access multiple databases with same grid
I need to be able to create and change database connections within OnRecord and other events so i can pull data in to rows as each one gets processed.

After working on this issue during the weekend here is more information I found.

Updating existing database connection on application init sometimes works but sometimes it does not.

For example if database connection “sc_conn” is used by the application and I add code to update this connection to different ip and user in on_scriptinit or on aplicationinit, scriptcase will still use old connection intimation when rendering the application. If i refresh the page it will use correct connection data. So it seems that system updates the connection but does not immediately use it as if it is caches some data and refuses to use new updated connection information. If you reload the application by refreshing the page it grabs updated info. So it is always one step behind, you open the page and see old connection information refresh the page and you see what should have seen first time.

This is definitely a problem because change of connection in for example onscriptiinit event should change connection info before sql request is made.

In some cases it does work, and it seems if you change location of the script and if you move connection update code from onscriptinit to onaplication init and back, but eventually it stop working and gets dellayed.

I t just seems like connection update actually happen at the end of application execution and not in the event I selected

Same problem here. I imported Apps and wanted to use them with new connection but no matter what I do they keep all connection and I get the same error message. It seem that simply connection change is not updated in internal SC9 SQLite database for some reason. This is quite serious isse because manipulating connection basically does not work.

Jena

Hi there! When using connection macros dynamically, you must use the macros to delete before they are initialized. sc_reset_connection_edit (); and sc_reset_connection_new ();
http://www.scriptcase.net/docs/en_us/v9/manual/14-macros/01-general-view/#sc_reset_connection_edit
http://www.scriptcase.net/docs/en_us/v9/manual/14-macros/01-general-view/#sc_reset_connection_new

I have problem with using connection inside Scriptcase IDE, I’m not using macros. So What am I supposed to do. One of the projects have this issue and I’m completely stuck. I do not have time to re-create App that have connection problem again from scratch.

hi…saw your topic on sc_connection_edit. can you help me resolve the following issue?
I am using sc_connection_edit in blank application and i need the data from edited connection immediately. sc_connection_edit works fine when we reload the application, but in my case scenario, i can not reload. the problem is sc_connection_edit is not connecting to revised database and fetching data from old database.

@skillbiz Idk if it can help, but I once needed a reload to get all elements drawn correctly when an SC form (but not blank) was open as modal

in the form onLoad event, I used this snipped I found googleing:


echo "
<script>
window.onload = function()
{
   /* if my var reload isn't set locally.. in the first time it will be true */
   if (!localStorage.getItem('reload'))
   {
      /* set reload locally and then reload the page */
      localStorage.setItem('reload', 'true');
      location.reload();
   }
   else
   {
      /* after reload clear the localStorage */
      localStorage.removeItem('reload');
      // localStorage.clear(); // an option
   }
}

</script>";

@robydago This is not working.