Database
Communication
using LabVIEW
Hans-Petter Halvorsen, M.Sc.
Software Software
All LabVIEW Software can be downloaded
Microsoft SQL Server Express can be from: www.ni.com/download
downloaded for free from Internet
Overview
ODBC
Microsoft
SQL Server Write/Read Data
Database
Database Management LabVIEW Application with GUI that
Communicate with the SQL Server
Create Tables
Database Systems
Hans-Petter Halvorsen, M.Sc.
Old fashion Database (Data-storage) Systems
Not too long ago, this was the only data-storage device most
companies needed. Those days are over.
Database Systems
• A Database is a structured way to store lots of information.
The information is stored in different tables.
• - “Everything” today is stored in databases!
Examples:
• Bank/Account systems
• Information in Web pages such as Facebook, Wikipedia,
YouTube, etc.
• … lots of other examples! (Give me 5 examples)
Database Management Systems (DBMS)
• Oracle
• MySQL
• MariaDB
• Sybase
• Microsoft Access
• Microsoft SQL Server
• ... (we have hundreds different DBMS)
SQL Server
Hans-Petter Halvorsen, M.Sc.
Microsoft SQL Server Software
Creating Tables
Table Name
SCHOOL
SchoolId Primary Key
Table Columns Name
Description
Lets Create the Example from Scratch
SQL
Structured Query Language
Hans-Petter Halvorsen, M.Sc.
What is SQL? Theory
• SQL – Structured Query Language
• SQL is a standard language for accessing
databases – and manipulate data
• SQL is not case sensitive
Example:
select SchoolId, Name from SCHOOL
We use the “SELECT” command in order
to get data from the Database
Table
Columns
Theory
SQL – Structured Query Language
Query Examples:
• insert into STUDENT (Name , Number, SchoolId)
values ('John Smith', '100005', 1)
• select SchoolId, Name from SCHOOL
• select * from SCHOOL where SchoolId > 100
• update STUDENT set Name='John Wayne' where StudentId=2
• delete from STUDENT where SchoolId=3
We have 4 different Query Types: INSERT, SELECT, UPDATE and DELETE
Lets Create some Examples from Scratch
Open Database Connectivity
(ODBC)
Hans-Petter Halvorsen, M.Sc.
ODBC
ODBC (Open Database Connectivity) is a standardized interface (API) for accessing
Theory
the database from a client. You can use this standard to communicate with
databases from different vendors, such as Oracle, SQL Server, etc. The designers
of ODBC aimed to make it independent of programming languages, database
systems, and operating systems.
Control Panel → Administrative Tools → Data Sources (ODBC)
We will use this ODBC Connection later
in LabVIEW in order to open the
Database Connection from LabVIEW
Note! Make sure to use the 32
bit version of the ODBC Tool!
ODBC – Step by Step Instructions
The Name of your
ODBC Connection
The Name of your
SQL Server
Select the Database
you are using
Use either Windows
or SQL Server
authentication Test your
(Windows is simplest connection to see
to use!) if its works
18
Lets Create the Example from Scratch
LabVIEW
Database Communication in LabVIEW
Hans-Petter Halvorsen, M.Sc.
LabVIEW SQL Toolkit
For Easy Database Communication using LabVIEW
Hans-Petter Halvorsen, M.Sc.
LabVIEW SQL Toolkit Software
Software
For Easy Database Communication using LabVIEW
© Hans-Petter Halvorsen
Download for free here:
http://home.hit.no/~hansha/documents/labview/code/SQLToolkit.zip
LabVIEW SQL Toolkit
Easy Access to Database Systems from
LabVIEW
Example 1: Get Data from Database into LabVIEW: 2D Table with Data
1 2 3
Query
Your ODBC
Connection Students: Try these Examples
Example 2: Write Data to Database from LabVIEW:
1 2 3
Query
23
Example 1: Get Data from Database
into LabVIEW
Lets Create the Example from Scratch
Example 2: Write Data to Database
from LabVIEW
Lets Create the Example from Scratch
Alternative Solution: Type in the
Connection String for your Database
Your Password for the sa user Type your Database here
Your SQL Server Instance
Your SQL Query
Note! When using this method, you dont need to create an ODBC Connection first!
LabVIEW Example
Logging Measurements Data to SQL Server
Hans-Petter Halvorsen, M.Sc.
Logging Measurement Data into
SQL Server Database
Temperature Measurements (TC-01 Thermocouple)
Note! You will need the NI DAQmx Driver
30
Logging Measurement Data into
SQL Server Database
Lets Create the Example from Scratch
Hans-Petter Halvorsen, M.Sc.
University College of Southeast Norway
www.usn.no
E-mail: [email protected]
Blog: http://home.hit.no/~hansha/