What connection string to use to connect to MySQL and SQL Server in atvise (Windows)

Created by Agent Aaron Camacho, Modified on Tue, 26 Aug at 7:21 PM by Agent Aaron Camacho

ODBC: Open DataBase Connectivity. The goal of ODBC is to make it possible to access any data from any application, no matter what management system it is.

DNS: Data Source Name. This is the name that applications use to request a connection to an ODBC Data Source. In other words, it is a symbolic name that represents the ODBC Connection.

MySQL:


        1. Before making the connection make sure you have either MySQL Server or SQL Server already installed in your computer. Create a database, a table and insert some values to the same.

 

        2. We need to configure the DSN, type ODBC in the search bar and make sure you are using the correct System type (32 or 64 bits) as below:

Interfaz de usuario gráfica, Texto, Aplicación

Description automatically generated

        3. Once opened go to “System DSN” and click on “Add…” as below:

Interfaz de usuario gráfica, Texto, Aplicación, Correo electrónico

Description automatically generated

        4. After that you will see the below options, select “MySQL ODBC 8.0 ANSI Driver” or “MySQL ODBC 8.0 Unicode Driver” to stablish the connection to MySQL server.

Interfaz de usuario gráfica

Description automatically generated

 

        5. Fill the text boxes with the corresponding information of MySQL and select the Database you would like to connect to. See below example:

Interfaz de usuario gráfica, Aplicación

Description automatically generated

 

        6. Once all the fields are entered click on “Test” to validate the connection is successful.

Interfaz de usuario gráfica, Aplicación

Description automatically generated

 

        7. Now the recently created connection should be visible in the System DSN tab as below:

Interfaz de usuario gráfica, Texto, Aplicación, Correo electrónico

Description automatically generated

 

        8. You will need to go to atviseBuilder->Library->PROJECT->Menu Scripts. Right click on “Menu Scripts” and select “Add Script” from the dropdown menu options.

Type the following code (remember the user and password you previously set in the ODBC Data Source) then click “Save and Run” :

var Client = new ODBCClient();

Client.source = "DSN=MySQLServer2; Uid=root;PWD=123456;";

if (Client.open()) {

              try

              {             // Ejecutamos el query SELECT

                             var resultado = Client.query("SELECT ID, Nombre FROM t_Persona");

                             console.log(resultado);                

                             // Organizamos los datos

                              var result = [];

                              for (var i=0; i<resultado.length; i++){

                                           result.push(

                                           {"ID": resultado[i][0],

                                           "Nombre": resultado[i][1],

                                           })

                              };

                              Client.close();

                              return (result);

              }

              finally

              {                                                                       

                             Client.close();

              }

}

              else

                             console.log("NOT connected to DB");

return undefined;


         9. Once you have typed the code in the script, click on “Save and Run”  a message like the below should appear:

Interfaz de usuario gráfica, Texto, Aplicación, Correo electrónico

Description automatically generated

SQL:

        10. The configuration for SQL Server is almost identical, to do so please repeat the steps 2 and 3, now you need to select the ODBC             driver, to know which driver works with your SQL version you can check the following website: https://www.connectionstrings.com/sql-server/

As I am using SQL 2019 I need to select the ODBC Driver 17 as below:

 

Interfaz de usuario gráfica, Texto, Aplicación

Description automatically generated 

 

        11. Once the driver has been selected, you click on finish and then proceed to fill the following fields with the corresponding information from SQL, see below as example:

Interfaz de usuario gráfica, Texto, Aplicación

Description automatically generated

 

Note: You can find the SQL Server name clicking “Connect” in the SQL Server Management Studio:

Interfaz de usuario gráfica, Aplicación

Description automatically generated

        12. Click on next to enter the User information as below:

Interfaz de usuario gráfica, Texto, Aplicación, Correo electrónico

Description automatically generated 

 

        13. Click next to select the default Database from the dropdown options as below:

Interfaz de usuario gráfica, Texto, Aplicación, Correo electrónico

Description automatically generated

 

        14. Once that has been done click on next and then finish.

Interfaz de usuario gráfica, Texto, Aplicación

Description automatically generated

        15. The following windows will appear:

 

Interfaz de usuario gráfica, Texto, Aplicación

Description automatically generated

 

 

        16. Make sure all the information is correct and click on “Test Data Source” to corroborate that the connection is working, if             everything is correct you should see below window:

 

Interfaz de usuario gráfica, Texto, Aplicación

Description automatically generated

 

        17. Click on OK and now you should be able to see the new connection listed as below:

 

Interfaz de usuario gráfica, Texto, Aplicación, Correo electrónico

Description automatically generated 

 

        18. Finally, you will need to go to atviseBuilder->Library->PROJECT->Menu Scripts. Right click on “Menu Scripts” and select “Add Script” from the dropdown menu options.

Type the following code (remember the user and password you previously set in the ODBC Data Source)

var Client = new ODBCClient();

Client.source = "DSN=MySQLServer2; Uid=root;PWD=123456;";

if (Client.open()) {

              try

              {             // Ejecutamos el query SELECT

                             var resultado = Client.query("SELECT ID, Nombre FROM t_Persona");

                             console.log(resultado);                

                             // Organizamos los datos

                              var result = [];

                              for (var i=0; i<resultado.length; i++){

                                           result.push(

                                           {"ID": resultado[i][0],

                                           "Nombre": resultado[i][1],

                                           })

                              };

                              Client.close();

                              return (result);

              }

              finally

              {                                                                       

                             Client.close();

              }

}

              else

                             console.log("NOT connected to DB");

return undefined;


        19. Once you have typed the code in the script, click on “Save and Run”  a message like the below should appear:

Interfaz de usuario gráfica, Texto, Aplicación, Correo electrónico

Description automatically generated


As you can see the once either MySQL or SQL is configured in the OBDC Data Source wizard from Windows the code in atvise is the practically same, the only thing you have to remember is the user and password you use when configuring the ODBC connections.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article