We will show how to extract MySQL data from a visual studio ASP NET application.

  • Install Apache 2 and MySQL on a Linux Server

We’ll use Ubuntu 20.04 LTS for the examples.

On a console window on the linux machine:

$ sudo su

# apt-get update

# apt-get upgrade

#apt-get install apache2 mysql-server

Execute:

# mysql-secure-installation, choose a password for the root user

Then:

# apt-get install php libapache2-mod-php php-mysql

Allow the necessary data exchange in the firewall configuration:

# ufw allow in “Apache Full”

# apt-get install php-cli

Test the php installation:

Create the file info.php in the /var/www/html folder, vith the content:

<?php

Phpinfo();

?>

Test this installation in your browser, executing:

http://yourIP/info.php

And you must view the classical php page with all the information.

  • Install PHPMyAdmin on the Linux Server

We need PHPMyAdmin to create a configure the database (if you don’t use the command line).

#apt-get install php-mbstring php-zip php-gd php-json php-curl phpMyAdmin

During the configuration select Apache2 as server (space to select, and then Tab)

Use dbconfig-common ? Yes

Insert the password for phpMyAdmin

In case of problems:

#dpkg-reconfigure phpMyAdmin

  • Create a database with PHPMyAdmin

Start PHPMyadmin in the browser (http://linuxmachineip/phpMyAdmin) and in the database tab select create a new database, give a name to the database, and press Create.

Create an ID field, of type INT, and a NAME field, of type VARCHAR. Insert some value (you can use the Insert Tab in phpMyAdmin).

  • Install Visual Studio from ®Microsoft

Moreover from the ©Microsoft Website, on a PC, download and install Visual Studio

  • Configure Visual Studio for the connection to MySQL

From the ©Oracle website download and install “MySQL for Visual Studio” and “MySQL Connector for Visual Studio”. Then launch Visual Studio and execute the configuration update tool.

  • Configure MySQL for remote access

From the Linux machine identify the file mysqld.cnf in the folder /etc/mysql/mysql.conf.d

There is a bind-address row, substitute:

bind-address 127.0.0.1 (local access)

with

bind-address 0.0.0.0 (remote access)

Or if you prefer add the IP of your windows PC only, for security reasons.

Then give the permissions to the firewall for the access from Visual Studio apps:

#ufw allow 3306

In addition create a remote user for the access from MySQL for Visual Studio:

#mysql -u root -p

>create user ‘myuser’@’localhost’ IDENTIFIED BY ‘mypass’;

>create user ‘myuser’@’%’ IDENTIFIED BY ‘mypass’;

>GRANT ALL ON *.* TO ‘myuser’@’localhost’;

>GRANT ALL ON *.* TO ‘myuser’@’%’;

>FLUSH PRIVILEGES;

>EXIT;

  • Create the Visual Studio application

Start Visual Studio and create a WebAppAspNET.

Drag a Database grid control on the design view of the default.asp file.

Configure the database connection from the grid control, adding the IP address of the linux host, the user and password, and the database name.

Use the Visual Studio wizard to create a personalized query (SELECT ID, NAME FROM TABLE). Note that if you have the fields between parenthesis, the query is not working with MySQL.

Test the application (Run or debug).

That’s all !

Leave a Reply