Connecting to a Remote SQL Database Using the LabVIEW NXG Web Module

Updated Apr 28, 2020

Reported In

Software

  • LabVIEW NXG Web Module
  • LabVIEW NXG
  • LabVIEW

Issue Details

I want to be able to connect to an SQL database from within the NXG Web Module and present the data by reading SQL tables/records from the database. How can I do this?

Solution

As of NXG 3.0, there is no direct database communication functions from within Web VIs, however there are some options utilizing other functions within LabVIEW in conjunction with Web VIs.

Web Services

Create a web service that handles the database communication, then use the WebVI to send HTTP requests to the web service to update/acquire database information like the following:

You can create the web service through LabVIEW (Current Generation, not NXG).  For an example on communication between LabVIEW Web Services and LabVIEW NXG Web VIs, refer to our GitHub example.  Keep in mind that while these are two separate entities (Web Service and Web VI), you can still have everything on the same computer by hosting the web service, and using the Web VI build output as static files in the web service.  The previous links are LabVIEW specific, but the same principle should apply with any other web service.  For more information on using existing web services, refer to Additional Information.

Additional Information

You can also use an existing web service that already communicates to an SQL database.  Some suggestions which may work for your purposes include PostgRest or restSQL.  The process would be similar to the above instructions using HTTP VIs as the bridge between the Web VI and the database