SQL Access
SQL Access
SQL Access
Summary
This article details how to configure an ODBC Data Source Name (DSN) for Microsoft Access
2000, and how to log data into a Microsoft (MS) Access database using SQL Access for
Wonderware® InTouch™ and the installed ODBC driver. The graphics contained in this article
were captured from a Windows 2000 Server machine. If you are not using this operating system,
the graphics will look different from the ones in this article.
Terminology
Before you continue reading the procedure, please familiarize yourself with some terms, and
their definitions, used throughout this article.
Term Definition
Database A collection of tables containing data.
Contains rows (database records) and columns (database fields) of
Table
information.
Bind List A map between InTouch tags and table columns.
Defines the table columns and their data types. A table template is
Table Template
used when you create a new table.
Data Source An alias which associates a database with an ODBC driver.
Stands for “Open DataBase Connectivity.” This is Microsoft standard to
ODBC
allow interconnectivity between different database formats.
The following step-by-step procedure describes how SQL Access is configured for Microsoft
Access.
1. Start MS Access.
2. Install SQL Access Manager, if you have not already done so.
c. On the ODBC Data Source Administrator dialog box, set up a new Data
Source by clicking the Add button.
o The Create New Data Source dialog box (Figure 2) will appear.
d. Once you have specified a new or an existing Data Source, the ODBC
Microsoft Access Setup dialog box (Figure 3) will appear.
e. Enter a Data Source Name (for example: SQLAM_Access) and click the
Select button.
g. Click OK.
FIGURE 5: THE ODBC MICROSOFT ACCESS SETUP DIALOG BOX - THE DATABASE SELECTION
4. Create an InTouch application with tagnames that are similar in name to the
column names in your MS Access database. Use the following tag types for the
corresponding MS Access data types:
Tag Type Used for the MS Access Data Type
Memory Integer Short and Long
Memory Real Float4 and Float8
Memory Message Text
6. Create an InTouch window to display and input the MS Access database column
values into the tags created in step 5. Create these Pushbuttons that are linked
to the PushButton Action scripts listed below:
Connect Pushbutton
Where:
1. <MyDSN> is the name you assigned for the ODBC Data Source Name.
3. <MyTemplate> and <MyBindList> are the names you assigned (or will
assign) for the SQL Access template file and Bind List.
Disconnect Pushbutton
CreateTable Pushbutton
ResultCode = SQLCreateTable( ConnectionId, TableName, TemplateName );
DropTable Pushbutton
Insert Pushbutton
Select Pushbutton
WhereExpr = "";
OrderByExpr = "";
ResultCode = SQLSelect( ConnectionId, TableName, BindList, WhereExpr,
OrderByExpr );
First Pushbutton
Prev Pushbutton
Next Pushbutton
Last Pushbutton
End Pushbutton
7. Create this Data Change script on the tag ResultCode to respond to errors in the
various SQL calls:
IF ResultCode == 0 THEN
ErrorMsg = "No errors occurred";
ELSE
ErrorMsg = SQLErrorMsg(ResultCode);
ENDIF;
o The Bind List associates the tagnames in your InTouch application to the
fields in the MS Access table that you want to reference.
o It is very important that the column names configured are not keywords
that are excluded from use for the SQL Access Bind List and the Table
Template, and the Open Database Connectivity (ODBC) interface.
o A list of those keywords are included in the Appendix of "The Intouch SQL
Access Manager User's Guide."
Note: If the column names in the table have spaces, then enclose the names
with square brackets ([ ]). For example, the column name "Employee ID" should
appear in the Bind List as [Employee ID]. In future InTouch releases the brackets
may not be necessary.
o This is where you will duplicate the column names, data type and size of
the MS Access database that you want to access.
Note: Again, enclose the column names with square brackets ([ ]) if the names have
spaces. In future InTouch releases the brackets may not be necessary.
FIGURE 7: THE TABLE TEMPLATE CONFIGURATION DIALOG BOX
Also, if your MS Access table name has spaces, then enclose the table name in single
quotes (for example: 'my table').
For most InTouch applications, the following steps on operating SQL Access are typical.
1. Start the WindowViewer and click the Connect button to perform an SQLConnect.
a. If SQLConnect is successful, then create the SQL Access table (if it does
not exist) by clicking the Create Table button.
2. Insert the records into the table by entering data in the Data Entry fields and
clicking the Insert Record button which executes the SQLInsert command.
3. Use the SQL Select to select records for viewing and editing.
a. This will create a temporary Results table which contains records that can
be browsed by using SQLFirst, SQLLast, SQLNext, and SQLPrev.
b. See Chapter 4 of "The SQL Access for InTouch User's Guide" for details.
4. After you browse the Results table, you can then free up the system resources
that were used by the Results table by executing the SQLEnd command. You
may also remove the SQL Access table by executing the SQLDropTable
command.
If a reserved keyword is used as the Column Name in a Bind List or Table Template, an error
message is generated in the Wonderware Logger. The type of error generated depends upon the
ODBC driver being used and the location in which the keyword is found. For example, one of the
most common errors made is using the DATE and TIME for Column Names in a Bind List or Table
Template. To avoid this error, use a slightly different name, e.g., "aDATE" and "aTIME."
The reserved keywords define the Structured Query Language (SQL) used by InTouch SQL
Access. The keywords are also recognized by the specific ODBC driver being used. SQL Access
passes the SQL command containing one or more reserved keywords to the ODBC.dll file. If the
SQL command cannot be interpreted correctly, SQL Access generates an error message in the
Wonderware Logger.