DatabaseCommunicationusingLabVIEW
Hans-PetterHalvorsen,M.Sc.
Software Software
MicrosoftSQLServerExpresscanbedownloadedforfreefromInternet
AllLabVIEWSoftwarecanbedownloadedfrom:www.ni.com/download
MicrosoftSQLServerDatabase
Overview
CreateTables
DatabaseManagement
Write/ReadData
ODBC
LabVIEWApplicationwithGUIthatCommunicatewiththeSQLServer
DatabaseSystems
Hans-PetterHalvorsen,M.Sc.
OldfashionDatabase(Data-storage)Systems
Nottoolongago,thiswastheonlydata-storagedevicemostcompaniesneeded.Thosedaysareover.
DatabaseSystems• ADatabaseisastructuredwaytostorelotsofinformation.
Theinformationisstoredindifferenttables.• - “Everything”todayisstoredindatabases!
Examples:• Bank/Accountsystems• InformationinWebpagessuchasFacebook,Wikipedia,YouTube,etc.
• …lotsofotherexamples!(Giveme5examples)
DatabaseManagementSystems(DBMS)• Oracle• MySQL• MariaDB• Sybase• MicrosoftAccess• MicrosoftSQLServer• ... (wehavehundredsdifferentDBMS)
Hans-PetterHalvorsen,M.Sc.
SQLServer
MicrosoftSQLServer Software
CreatingTables
SchoolIdNameDescription
SCHOOLTableName
TableColumns
PrimaryKey
LetsCreatetheExamplefromScratch
StructuredQueryLanguageSQL
Hans-PetterHalvorsen,M.Sc.
WhatisSQL?• SQL– StructuredQueryLanguage• SQLisastandardlanguageforaccessingdatabases– andmanipulatedata
• SQLisnotcasesensitive
select SchoolId, Name from SCHOOL
ColumnsTable
Example:
Weusethe“SELECT”commandinordertogetdatafromtheDatabase
Theory
SQL– StructuredQueryLanguage
• 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
QueryExamples:
Wehave4differentQueryTypes:INSERT,SELECT,UPDATEand DELETE
Theory
LetsCreatesomeExamplesfromScratch
Hans-PetterHalvorsen,M.Sc.
OpenDatabaseConnectivity(ODBC)
ODBCODBC(OpenDatabaseConnectivity)isastandardizedinterface(API)foraccessingthedatabasefromaclient.Youcanusethisstandardtocommunicatewithdatabasesfromdifferentvendors,suchasOracle,SQLServer,etc.ThedesignersofODBCaimedtomakeitindependentofprogramminglanguages,databasesystems,andoperatingsystems.ControlPanel→AdministrativeTools→DataSources(ODBC)
WewillusethisODBCConnectionlaterinLabVIEWinordertoopentheDatabaseConnectionfromLabVIEW
Theory
Note!Makesuretousethe32bit versionoftheODBCTool!
ODBC– StepbyStepInstructions
18
TheNameofyourSQLServer
TheNameofyourODBCConnection
UseeitherWindowsorSQLServerauthentication(Windowsissimplesttouse!)
SelecttheDatabaseyouareusing
Testyourconnectiontoseeifitsworks
LetsCreatetheExamplefromScratch
DatabaseCommunicationinLabVIEWLabVIEW
Hans-PetterHalvorsen,M.Sc.
Hans-PetterHalvorsen,M.Sc.
LabVIEWSQLToolkitForEasyDatabaseCommunicationusingLabVIEW
LabVIEWSQLToolkit
http://home.hit.no/~hansha/documents/labview/code/SQLToolkit.zip
ForEasyDatabaseCommunicationusingLabVIEW
©Hans-PetterHalvorsenDownloadforfreehere:
SoftwareSoftware
LabVIEWSQLToolkit
23
Example1:GetDatafromDatabaseintoLabVIEW:
Example2:WriteDatatoDatabasefromLabVIEW:
EasyAccesstoDatabaseSystemsfromLabVIEW
YourODBCConnection
2DTablewithData
1
Query
Query
2 3
1 2 3
Students:TrytheseExamples
Example1:GetDatafromDatabaseintoLabVIEW
LetsCreatetheExamplefromScratch
Example2:WriteDatatoDatabasefromLabVIEW
LetsCreatetheExamplefromScratch
AlternativeSolution:TypeintheConnectionStringforyourDatabase
Note!Whenusingthismethod,youdontneedtocreateanODBCConnectionfirst!
YourPasswordforthesauser
YourSQLServerInstance
TypeyourDatabasehere
YourSQLQuery
Hans-PetterHalvorsen,M.Sc.
LabVIEWExampleLoggingMeasurementsDatatoSQLServer
LoggingMeasurementDataintoSQLServerDatabase
30
TemperatureMeasurements(TC-01Thermocouple)
Note!YouwillneedtheNIDAQmxDriver
LoggingMeasurementDataintoSQLServerDatabase
LetsCreatetheExamplefromScratch
Hans-PetterHalvorsen,M.Sc.
UniversityCollegeofSoutheastNorwaywww.usn.no
E-mail:[email protected]:http://home.hit.no/~hansha/