Press Release
TECHNICAL NOTE
TNOI41
Title: SQL Synchronization
Product(s): G308, G310, G315
INTRODUCTION
Crimson 3 now allows G308, G310 and G315 HMIs to sync their data log files to a SQL Database. This
eliminates the need for user intervention or custom scripts to get the logged data into a database.
BACKGROUND
The Red Lion unit uses the Tabular Data Stream (TDS) protocol to communicate to the SQL Server via
TCP/IP. In order for the Red Lion unit to be able to establish the connection to the server, the PC running the
server will need to have a rule in place for its firewall to allow traffic going to the defined TCP port to pass
through (the default port is 1433). Another option, although less desirable, would be to disable the firewall.
SQL SERVER CONFIGURATION
Open SQL Server Configuration Manager. In the left pane, expand SQL Server Network Configuration and
select Protocols for MSSQLSERVER. Double-click TCP/IP in the right pane to open TCP/IP Properties. Set
“Enabled” to “Yes” to enable the TCP/IP connection to the server.
After clicking “Apply” or “OK,” a popup will inform you that the changes will not take effect until the service
is restarted. In order to restart the service, click on SQL Server Services in the left pane of SQL Server
Configuration Manager. In the right pane, find the item named SQL Server (MSSQLSERVER), right click it and
choose “Restart”.
CRIMSON 3.0 CONFIGURATION
Click on SQL Sync listed under Services in the Communications section of Crimson 3. Enable SQL Sync and fill
in the parameters for the server and the database name. The Table Name Prefix is optional; this allows you to
create several tables in the same database, which allows you to separate data from different units. The table
name prefix will be prepended to the log file name to create the SQL Server table name. Data Synchronization
allows you to specify how often to sync the logs to the database. Sync Delay would be used in cases where
there is more than 1 unit syncing to the server. This allows you to stagger them so they are not all trying to
connect to the server simultaneously. Record Log File is only needed for troubleshooting purposes and should
NOT be left on during normal operation. The log file is described later in this document.
SQL SYNC EXECUTION
At the time of the sync period and delay, the SQL Sync service will attempt to connect to the SQL Server via
the configured IP and TCP/IP port. The messages sent to the SQL Server use the TDS protocol specified by
Microsoft. Once connected, a logon request will be sent to the SQL Server using the configured username and
password. After connecting, the service will scan for all logs in the “LOGS” directory on the CF card. For each
log, the service will process any log files that have been updated or newly created since the last time the
service executed. The service creates a timestamp file named “TIMEDATE.BIN” in each log directory to
record the timestamp of the last record processed for that log. The service will automatically identify the table
name and column names from the log file. The table name will consist of the configured table name prefix (if
any) prepended to the log name using an underscore, „_‟ . The service will attempt to create the table
automatically in SQL Server if it does not already exist. Column names correspond to the tag names at the top
of the log file. The column type is determined by the type of the tag in the Crimson 3 runtime. The tags
therefore must continue to exist in the C3 database while executing. Any tag that does not exist will default to
a SQL Server data type of VARCHAR(256). Also, modifying a C3 database by changing the tags in a log
without renaming the log itself will cause the SQL Sync to fail for that log, since the column names for the
table will have changed. You must drop the existing table in the database to fix this issue. Column names
containing „.‟ or „[„ will be replaced with a „_‟ . Ending „]‟ will be omitted. So, for instance, an array tag of
“Array1[0]” will be converted to a column name of “Array1_0”. The service will next attempt to extract rows
of data from the log‟ s CSV files. Each row in the CSV file will become a new row in the SQL Server
database table for that log. Note that the date and time columns are combined into a single date/time column in
the SQL Server table. After all logs are processed, the SQL Server connection is closed.
FORCING SQL SYNC WITH A FUNCTION CALL
Normally, the SQL Sync service will execute periodically to synchronize log files with the SQL Server.
However, if the Manual Sync option is set to Yes, the service will only synchronize when the function
ForceSQLSync() is called. In this case, calling the function will force synchronization regardless of the
configuration for Sync Period and Sync Delay.
SQL SYNC LOG FILE
If Record Log File is enabled, the SQL Sync service will create a log of its actions on the CF card and of any
errors it encounters. The log file is called “SQL.LOG” and appears in the root directory of the CF card. This
feature can be useful in debugging issues with SQL Server synchronization. Note, however, that there will be
slight performance degradation because of the extra writes to CF. The log file will show the log processed,
each file processed, the last timestamp previously processed for that log, the column names and data types, and
the commands issued to create the table and transfer the data. All log entries are time stamped. Errors will
appear with the word ERROR in front, the internal function name in brackets and the error message. For
example, in the case of failure to connect to the SQL Server, the error will appear as follows:
“2011/05/02 13:56:32 ERROR: [ProcessAllLogFiles] Error Opening Socket”
INSTALLING SQL EXPRESS
SQL Express is a free (limited) version of SQL that can be used for demo purposes. You can download it from
Microsoft using this link: http://www.microsoft.com/express/Database/
The install is relatively straight forward, but there are two items that need to be changed from the default
settings. SQL Express does not install as the default instance, which is required in order for the Red Lion unit
to sync with the server as we cannot sync to a named instance. There is a check box that gives the option to
choose a named or default instance.
The other item is the authentication method, which defaults to Windows authentication mode. The Red Lion
unit cannot support this mode—it requires SQL Server authentication. When you select the Mixed Mode
option, you then need to specify the password for the administrative account.
SQL SERVER CONFIGURATION
Open SQL Server Configuration Manager. In the left pane, expand SQL Server Network Configuration and
select Protocols for MSSQLSERVER. Double-click TCP/IP in the right pane to open TCP/IP Properties. Set
Enabled to Yes to enable the TCP/IP connection to the server.
After clicking Apply or OK, a popup will inform you that the changes will not take effect until the service is
restarted. In order to restart the service, click on SQL Server Services in the left pane of SQL Server
Configuration Manager. In the right pane, find the item named SQL Server (MSSQLSERVER), right click it and
choose Restart.
CREATING A DATABASE
The Red Lion unit needs to be given the name of the database that it will be writing to, so you will need to
create a database. Open Microsoft SQL Server Management Studio and connect to the server. Right-click on
Databases and choose New Database….
Give the database a name and click OK.
After the G3 syncs to the server, you should see a new table below the specified database on the left pane of
Microsoft SQL Server Management Studio.
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertising