Announcement

Collapse
No announcement yet.

sc_connection_edit() do not work in prod ????? urgent

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • sc_connection_edit() do not work in prod ????? urgent

    Hello,

    I have added this in my login screen : user enter a company name in{dbcompany} and I select corresponding database

    $mdbname = {dbcompany};
    $arr_conn['database'] = trim($mdbname);

    sc_connection_edit("conn_mysql", $arr_conn);

    It's working when I deploy in my development environnment, but not in prod env on my web server (centos) : first database is selected always????

    I am on version 8.0.0.27
    Thanks for yours helps
    Nac

  • #2
    Nac,

    A couple of things to check:

    1. Did you update the standard libraries on your production server when you updated scriptcase? Version 8.0.015 had a bug that behaved exactly like you describe - Read This

    2. During an application's Initialization, all connections used by that application get opened, consequently any changes you make to a connection after that initialization will only be used when the next application goes through its initialization and opens the connection again. The generated source, for example for a form, has the relevant code in init(), prep_connect(), conectDB(), and conectExtra(); I have had some success in making direct calls instead of using sc_connection_edit until they get around to fixing it. I needed to have a connection change during the onRecord event of a grid so that each line of the grid could get data from a different database. With sc_connection_edit being broken, I coded a workaround. I put a demo of the bug as well as a workaround in a project. Read this

    Dave
    Last edited by daveprue; 01-13-2015, 08:04 AM.
    Dave Prue
    Code Whisperer
    Lahar International Corp
    www.lahar.net

    Comment


    • #3
      Hi Dave

      It's a control form , in OnValidate event

      Thanks
      Nac

      Comment


      • #4
        Sorry, I was updating my answer at the same time you were posting
        Dave Prue
        Code Whisperer
        Lahar International Corp
        www.lahar.net

        Comment


        • #5
          Thanks Dave

          Before installing my v8 in prod , I deleted everything to have a new installation.
          I installed with all common librairies

          I think this bug was not really resolved !!!!

          Nac

          Comment


          • #6
            Nac,

            Yes, the Development/Production bug was solved, I have many users that get assigned to one of 75 databases when they log in, and all of the applications after the login app show the new database.

            The one thing that perhaps I am doing differently than you is that I have multiple connections. For example, the login app has a default connection I call "system" which I never modify. I have another connection, called "account" which is the connection that I modify, and use as the default connection on most of the grids and forms in the system. All of that has worked well since 8.0.016, the same in Development/Production. When they updated from 8.0.015 to 8.0.016 though, I had to update the common libraries manually, because some part of the fix was in those libraries.


            Dave
            Dave Prue
            Code Whisperer
            Lahar International Corp
            www.lahar.net

            Comment


            • #7
              What to do mean by " update common librairies manually" ?
              I use always winscp for manually copying all my directories to deploy

              Strange that it's working on develop env and not in prod env ??

              Comment


              • #8
                Hello,

                Please clear your /scriptcase/tmp folder, regenerate all apps then deploy your project again and let me know if the issue continues.

                regards,
                Bernhard Bernsmann

                Comment


                • #9
                  Hello Bernhard

                  I will try this !!

                  Thanks
                  Last edited by nacyil; 01-14-2015, 05:18 AM.

                  Comment


                  • #10
                    Hello Dave

                    I made your solution, I create an other connection for my login screen and use conn_mysql in sc_connection_edit and it's work ??

                    Thanks
                    Nac

                    Comment


                    • #11
                      Hello Dave

                      There is something strange anywhere, when I change the database user validation is incorrect :

                      $arr_conn['database'] = trim($mdbname);

                      sc_connection_edit("conn_mysql", $arr_conn);
                      sc_change_connection("system","conn_mysql");

                      $slogin = sc_sql_injection({login});
                      $spswd = sc_sql_injection(md5({pswd}));

                      $sql = "SELECT priv_admin,active, name, email,themes_name FROM sec_users WHERE login = $slogin AND pswd = ".$spswd."";

                      sc_lookup(rs, $sql);

                      The problem is :
                      I connect with my login and pwd in 1st database, I quit and connect to an another database but with same login and pwd (this user does not exist in 2nd db) but its accepted.
                      I quit and try to connect again to 2nd db always with same login and pwd , at this point it doesn't find this user ???

                      Hope my explanation is clear enough !!!
                      Nac

                      Comment


                      • #12
                        Originally posted by nacyil View Post
                        Hello Dave

                        There is something strange anywhere, when I change the database user validation is incorrect :

                        $arr_conn['database'] = trim($mdbname);

                        sc_connection_edit("conn_mysql", $arr_conn);
                        sc_change_connection("system","conn_mysql");

                        $slogin = sc_sql_injection({login});
                        $spswd = sc_sql_injection(md5({pswd}));

                        $sql = "SELECT priv_admin,active, name, email,themes_name FROM sec_users WHERE login = $slogin AND pswd = ".$spswd."";

                        sc_lookup(rs, $sql);

                        The problem is :
                        I connect with my login and pwd in 1st database, I quit and connect to an another database but with same login and pwd (this user does not exist in 2nd db) but its accepted.
                        I quit and try to connect again to 2nd db always with same login and pwd , at this point it doesn't find this user ???

                        Hope my explanation is clear enough !!!
                        Nac
                        Nac,

                        At first glance, the problem that you are having should be fixed if you change sc_lookup(rs, $sql) to sc_lookup(rs, $sql, "system") however it would appear to me that you are planning multiple databases each with its own users file. I would not do it that way.

                        In my environment, I use a single database for all user logins, and multiple (~75) identically structured databases for the remainder of the system. This is so that I can store the database connection information in the user's login record.

                        I use "system" as the default database connection for the login app, and "account" as the default database connection for the remainder of the apps. When I read the users table from the login app, I load the database connection info from the users's table.

                        I code it like this:

                        Code:
                            $slogin = sc_sql_injection({login});
                            $spswd = sc_sql_injection(md5({pswd}));
                        
                            $sql = "SELECT db_server,db_name,db_user,db_password,priv_admin,active, name, email,themes_name FROM  sec_users WHERE login = $slogin AND pswd = ".$spswd."";
                        
                            sc_lookup(rs, $sql, "system");
                        
                            // Check for errors here of course...
                        
                            $arr_conn['server'] = $rs[0];
                            $arr_conn['database'] = $rs[1];
                            $arr_conn['user'] = $rs[2];
                            $arr_conn['password'] = $rs[3];
                            sc_connection_edit("account", $arr_conn);  
                        
                            // Since all the rest of the applications use "account" as their default connection, the user is now using the proper database
                            // We have not messed with "system", so that can still be used as default for the apps that add/edit users, and things like that.
                        This, of course, requires that you have already manually created connections called "system" and "account", and that the default connection for login app is "system" and all the applications after the login app have default connection "account". (This is not strictly true, because I have apps to add and edit users, etc., that also use the "system" connection).


                        Slightly different topic:

                        If you want to programmatically access a database in the same application where you are changing the database, then you need to do things a bit differently:

                        Code:
                        // We are going to use a connection called "special".  
                        // Whatever connection you choose:
                        //              1.  CANNOT be the default connector for this application.
                        //              2.  Must have a connection by this name already existing.
                        // Notice below the name of the array in the Ini object is "nm_con_special" because our connector is named "special"
                        // If your connector is named differently, then change the array name.
                        
                            $this->Ini->nm_con_special['servidor'] = $server;
                            $this->Ini->nm_con_special['banco'] = trim($mdbname);
                            $this->Ini->nm_con_special['usuario'] = $user;
                            $this->Ini->nm_con_special['senha'] = encode_string_utf8($password);
                            $this->Ini->conectExtra();
                        
                        $sql = "SELECT [something] FROM [table] WHERE [condition]";
                        sc_lookup(rs, $sql, "special");  // You MUST specify the connector here!!
                        Also, please note that this will all change if/when NetMake gets around to fixing the bug.

                        Dave
                        Last edited by daveprue; 01-15-2015, 01:29 AM.
                        Dave Prue
                        Code Whisperer
                        Lahar International Corp
                        www.lahar.net

                        Comment


                        • #13
                          Thanks Dave

                          Comment

                          Working...
                          X