Database Connectivity using MySQL
In this tutorial we will see how to open connection for database and the various methods for opening connection. Connection should be closed at the end.
In LabVIEW functions palette, Database VI’s are located in Connectivity >>Database.
Turn ON the MySQL server in MySQL workbench if not running.
First step is to open Connection to the database by wiring connection information in “DB Tools Open Connection.vi”. Input can be any of the following.
- DSN name
- Udl path
- Connection string
Connection Information input has to be given for “DB Tools Open Connection.vi”. DSN name, Connection String or Udl path can be given. Be careful when you give udl path when creating application. Below is an example which shows the possible inputs which can be given for opening connection.
CREATE DSN [Data Source Name]:
- Create DSN by going to Control Panel -> Administrative Tools ->DataSources(ODBC)
- Click Add to create New User DSN [Specific to User whereas System DSN is for all users in that PC] which prompts a window to select a data source.
- Select Finish and configure ODBC by giving Data Source Name, TCP/IP Server [localhost-if the server is in same PC or else give ip address of MySQL server], user name, password and database name.
Click Test to test the connection. It will show connection successful message. Then Click OK.
Right click on windows and create new text document and save as MyUdl.udl
Open MyUdl.udl and select Provider.
Now configure for the connection.
And test the connection.
Connection string can be obtained by two ways. One is from udl file and the other from LabVIEW.
- Open Udl file, select Connection tab and select Connection string and click build. Select the DSN name under Machine Data Source tab and click OK.
- In LabVIEW,