How to Connect LabVIEW to a Database

Updated Mar 16, 2023

Reported In

Software

  • LabVIEW
  • LabVIEW Database Connectivity Toolkit

Issue Details

  • I need to connect my LabVIEW application to a database to store and query measurement data and configuration information. What is the simplest way to do that using LabVIEW?
  • What tools can I use in LabVIEW to communicate with a database?

Solution

The best and easiest way to perform database connection and operations in LabVIEW is by using the LabVIEW Database and Connectivity Toolkit. This comes with a simple API that allows for the creation of routines that work with the most popular databases. These include:
  • Microsoft Access
  • SQL Server
  • Oracle
The Database and Connectivity Toolkit also provides a set of advanced functions to access low level operations.

Sample code that exemplifies the usage of this Toolkit can be found below. This is a native example that comes with the Toolkit, and can be found by clicking Help>> Find Examples >> Toolkits and Modules >> Database Connectivity.

Read All Data Snippet.png
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

When communicating with a database, the general workflow will be:
Open a connection to the database -> manipulate data (i.e. inserting tables, fetching Recordsets and executing queries) -> Close the database connection.

This workflow can be achieved using the LabVIEW Database Connectivity Toolkit VIs.

Additional Information

Alternatively, the 3rd party LabSQL VIs can be used to establish a connection with a database in LabVIEW.
Note: NI is not responsible for LabSQL and does not offer technical support for it's use.