Connect to a MS SQL Server database

Jump to


The function module needed to connect to SQL server from PC Worx is pc_worx_6_x_dbfl_sql_1_20.exe .

If the link doesn’t work anymore, go to Products > Software > Programming > Product list Programming > Software – PC WORX DEMO – 2985725 and select Downloads tab. Then use Ctrl+f to find it, just typing sql would be enough.

An example containing insert and select POUs can be found on the same page, find database.


Settings to be done

The easiest way is to start from the example provided by Phoenix Contact. After opening it, make sure you replace the resource with your physical PLC or use PC Worx SRT, as you wish. The example is fully functional and will allow you to check if managed to set up correctly the connection.

Check the SQL Server and firewall settings as instructed here.

Edit the POU with the new connection info

If you are working in the application example provided by Phoenix Contact, you need to change in both *main* POUs the following variables:

  • strDataBaseUser – add the user you created in SQL
  • strDataBasePassword – the password you set for this user
  • strDataBaseIPAdress – the IP of the machine holding the SQL server
  • strDataBaseIPPort – 1433 is the default for SQL server, if you defined other, type that one.

Now it should work.