CPS - Database with MS SQL Server Manual_20191126_EN
CPS - Database with MS SQL Server Manual_20191126_EN
DATABASE MANUAL EN
Table of Contents
Preliminary steps ..................................................................................................................................... 3
Configuring SQL Server 2008 R2 Express Edition for remote access....................................................... 3
Firewall configuration.......................................................................................................................... 9
Configure the required firewall ports................................................................................................ 12
Configuration options for SQL Server Reporting Services ................................................................. 15
Enabling SQL authentication and sa user for database login ................................................................ 21
To Change the Authentication Mode: ............................................................................................... 21
Notes for SQL Server 2012 and later versions....................................................................................... 26
CPS Installation with MS SQL database ................................................................................................. 27
Backup and restore of the CPS database with MS SQL Server .............................................................. 30
Backing up ......................................................................................................................................... 30
Restoring ........................................................................................................................................... 32
Used ports information ......................................................................................................................... 37
CPS database tables’ explanation for sensors ....................................................................................... 39
Finding sensor data in the CPS database .............................................................................................. 45
We’ll cover these steps below, using this blog as the source for information:
http://akawn.com/blog/2012/01/configuring-sql-server-2008-r2-express-edition-for-remote-
access/
Also included are the additional configuration steps for SQL Server 2008 R2 x64 Express Edition with
Advanced Services.
Start the SQL Server Configuration Manager from the Start menu, and choose Services.
Below you can see that by default, SQL Server Express allocates a Dynamic port when SQL Server
starts.
You can either keep this setting or change SQL Server to listen on a fixed TCP port e.g. TCP 1433. This
can be achieved by removing 0 from all the ‘TCP Dynamic Ports’ rows and placing the fixed TCP port
you want to use on all the ‘TCP Port’ rows below it.
For this demo we will keep SQL Server allocating a Dynamic port on start-up and therefore we
have not changed anything on this tab.
As below you can see the instance when SQL Server Express is installed is called SQLEXPRESS if you
did not change it.
The below should already be enabled, but if it isn’t, then enable it and restart the SQL Server service.
Choose Port
If you changed the HTTP TCP port from the default on 80, then you should enter the port you are
using here.
Add the relevant windows user with the permissions they require.
https://sudeeptaganguly.wordpress.com/2010/04/20/how-to-enable-sa-account-in-sql-server/
When you install the SQL Server using Windows Authentication mode, by default, the “sa” account is
disabled. Sometimes, due to users/customers request, you may need to enable the sa account. You
need to change the authentication mode for SQL server from Windows Authentication Mode to SQL
Server and Windows Authentication Mode to use the sa account.
You need to remember that, the SQL Server service needs to restart to make this change effective.
1. Login to the SQL server instance using SQL Server Management Studio.
Click on the radio button next to SQL Server and Windows Authentication mode, and click on OK to
close the Server Properties page.
3. Once you clicked on the Ok button, we will get the following screen:
As discussed earlier, we need to restart the SQL Server service to make this change effective.
After restarting the SQL Server, the authentication mode will be changed to SQL Server and Windows
Authentication mode.
1. Connect to the SQL Server instance using SSMS and go to Security. Expand Security, go to Logins.
2. You can see the sa account is disabled when you install SQL Server using Windows Authentication
mode.
By default, the Enforce password policy is checked. (if you don’t want to provide a complex password
for the sa account, you can uncheck this option. However, this is not recommended.)
If you want to use a script to enable the sa account, you can use the script mentioned below:
1: USE [master]
2: GO
3: ALTER LOGIN [sa] WITH PASSWORD=N'z43VGYT@Iu*60i'
4: GO
5: ALTER LOGIN [sa] ENABLE
6: GO
The configuration process for SQL Server 2012 is the same as with the 2008R2 version, except that
the SQL Server Configuration Manager is not added to the Start menu (in the 2014 version, it’s
added again).
Microsoft has further hardened the permissions of SQL Server, hence the SYSTEM user has less rights
in a default configuration. This can result in the CPS service unable to start automatically.
As a fix, modify the user’s rights that run the CPS service (by default the SYSTEM user) to include the
sysadmin right:
1. Open the SQL Server Management Studio and login as an SQL administrator.
3. Find the user that runs the CPS service. By default this is the NT AUTHORITY\SYSTEM user.
4. Open the properties, go to the Server Roles page, and click the sysadmin privilege, then press OK.
Important: if you’re not using the default DB instance but a named instance, you must specify it,
otherwise the connection will fail!
In our test machine, the SERVER_NAME is Win2008R2 and the INSTANCE_NAME is SQLEXPRESS as
we’ve used the Express version.
Authentication: Windows or SQL. This setting depends on your installed SQL server; by default newer
versions are using the Windows authentication method as default.
Note: if you use SQL authentication, the ODBC connection’s user and password will be saved
(encrypted) in the CPS configuration file server.xml.
You can verify that the CPS database has been created in SQL Management Studio, the CPS database
is named “server”:
On a 64-bit OS, start odbcad32.exe from C:\Windows\SysWOW64; the file in the System32 directory
is the 64-bit version, which can’t show the 32-bit connectors on Windows Server 2008 and R2.
Note: On Windows Server 2012 and up, you will be able to see the data source but can’t modify it
using the 64-bit ODBC manager.
If you choose external DB then you’ll have to use that software’s backup/restore functions.
Below we’ll cover the instructions for MS SQL (manual method only).
Backing up
To get a consistent state of the backup, it’s recommended to first stop the CPS services using the
CONTEG Pro Server Manager.
Choose the server DB from the list, and select Tasks / Back Up…
You could modify the backup file’s target, by default it goes to the SQL Server’s Backup directory.
Start the SQL Management Studio and connect to the DB instance which stores the CPS databases
(server and syslog).
Right click on the Databases folder tree and select Restore Database…
After the DBs have been restored, you can start the CPS service again.
Important note: Renaming the DB instance and the server is not supported! If you attempt to do so,
you’ll get the following error and CPS cannot start:
The connector is under the System DSN tab. Click on Configure… then Next and choose Client
Configuration…
You can check and change this in the CPS Server Manager program, or under the CPS client Settings
menu / Server Options / Connections.
Note: In MS SQL database, these table names have a prefix dbo. for example: dbo.host
Note 2: We’ve only included the listed reserved/unused values in case you encounter a very old DB
that still has these values; it's not an error if you see them.
Note 3: If the DB has some columns where the data type mismatches with the types written in this
manual (INTEGER or VARCHAR, and length), that could mean you have a DB Sync issue or some other
DB error.
1. host - contains all the network devices (including non- Intelligent RAMOS) under
Monitoring/Sensors in CPS.
hostid (INTEGER, primary key) - CPS DB sequence number, unique for each device
type (INTEGER) - the device’s type, see below for possible values
port (INTEGER) - SNMP monitoring port - note: the default port is also added for non-SNMP devices
0 = Unknown Device
1 = Network Device
3 = Ramos Optima
6 = Axis Camera
7 = reserved/unused
8 = reserved/unused
9 = IP Camera
10 = Ramos Ultra
15 = Quaddrix IP Camera
17 = reserved/unused
18 = Template Device
hostid (INTEGER, primary key) - matches the hostid in the host table, per unique device
name (VARCHAR, primary key) - each device (hostid) can have multiple properties, these are listed
here - for example: httpport, dhcp_enable, syscontact, firmware_version
value (VARCHAR, 4000) - the string value for each “name” field - following the previous example in
order: 80, 0, System Contact, SEC-MX25V405a
Example:
name value
httpport 80
dhcp_enable 0
syscontact System Contact
firmware_version SEC-MX25V405a
3. board - contains all board devices for each network device (every Intelligent RAMOS device that
has at least a base board) and expansion boards
hostid (INTEGER) - matches the hostid in the host table, per unique device
boardid (INTEGER, primary key) - CPS DB sequence number, unique for each board
board prop id (INTEGER) - remote board id; the boardid in a device's own database, its value will
match the board_ref_id property string in the boardprop table
property update id (INTEGER) - used for checking that a board’s property is modified or not; it will be
1 for the first time when you add an Intelligent RAMOS device to CPS, and increment when you edit a
board- or sensor’s setting
4. boardprop - contains the boards’ property string values, such as expansion board name and type
boardid (INTEGER, primary key) - matches the boardid in the board table, per unique board
name (VARCHAR, 30, primary key) - each board (boardid) can have multiple properties, these are
listed here - for example: desc, board_enable, type, revision
value (VARCHAR, 4000) - the string value for each “name” field - following the previous example in
order: Main Module, 1, 8, 2
name value
desc Main Module
board_enable 1
type 8
revision 2
1 = EX-I8 board
3 = EX-O16 board
9 = RDU board
10 = EX-D64 board
11 = EX-D128 board
12 = EX-D192 board
hostid (INTEGER) - matches the hostid in the host table, per unique device
serviceid (INTEGER, primary key) - CPS DB sequence number, unique for each sensor
type (INTEGER) - the sensor’s type, see below for possible values
port (INTEGER) - the sensor’s port on a device; it can be physical or virtual, also for daisy chained
sensors
boardid (INTEGER) - matches the boardid in the board table, per unique board
rboardid (INTEGER) - remote board id; references the boardid on a remote device and matches the
board_prop_id in the board table, it is used when CPS communicates with an Intelligent RAMOS
device - CPS Server and CPS Client uses the boardid for communication
CPS Server <--> CPS Client uses boardid / sensorid for communication
Device (SEC) <--> CPS Server uses rboardid / rsensorid for communication
2 = 4-20 mA
3 = Humidity
4 = Water Detector
5 = Digital Voltmeter
6 = Security
8 = Airflow
10 = Dry Contact
12 = AC Voltage
13 = Relay
14 = Motion Detector
15 = unused/reserved
20 = unused/reserved
21 = unused/reserved
23 = Thermostat
24 = Smoke Detector
25 = Power
26 = RMS Current
27 = RMS Voltage
28 = Watt Meter
30 = Virtual Sensors
32 = Watt-Hour Meter
33 = Temperature Array
34 = Liquid Rope
37 = Door
39 = Reader
40 = Probe Switch
41 = Time Tracking
42 = Tamper
43 = Thermocouple
45 = Vibration
46 = Power Voltage
144 = Camera
61702 = Map
61703 = Recording
6. serviceprop - contains the sensors’ property string values, such as status description and sensor
unit
serviceid (INTEGER, primary key) - matches the serviceid in the service table, per unique sensor
name (VARCHAR, 30, primary key) - each sensor (serviceid) can have multiple properties, these are
listed here - for example: desc, on_desc, normalstate, ping_method
value (VARCHAR, 4000) - the string value for each “name” field - following the previous example in
order: Host Status, Unreachable, 0, 0
Example:
name value
desc Host Status
on_desc Unreachable
normalstate 0
ping_method 0
We’ll use the default SQLite DB format and the SQLite Database Browser program for demonstration
purposes (downloadable from http://sqlitebrowser.org/).
This requires checking 3 database tables: hostid (devices), service (sensor IDs), and serviceprop
(sensor properties).
1. Open server.db file with the browser, and look through the host table to find the RAMOS OPTIMA
device (we looked for its IP address in the name field):
This hostid has 3 serviceid values: 355, 356, 357. We’ll look for these in the serviceprop table.
3. Browse the serviceprop table and look for the serviceid values:
Based on this information, you can get the serviceid value for a given sensor.
verze