Querying the Historian using a Linked Server in Microsoft SQL Server (version 23)
Configuring the Linked Server
- Ensure the ODBC Service is installed/licensed on the Canary Historian and the ODBC client is installed on the SQL server.
- Open Microsoft SQL Server Management Studio and right-click 'Linked Servers' to create a 'New Linked Server'.
- Name the linked server. In this example, we are using 'CANARY'.
- Select 'Microsoft OLE DB Provider for ODBC Drivers' from the Provider drop-down list.
- Set the Data source to 'CanaryODBCClient'.
- Optional - If security is enabled within Views, a username/password can be provided through the 'Security' tab of the Linked Server. (*Note, this user account will overwrite the user account configured in the ODBC Data Source Administrator. See Installing the ODBC Client.)
- Click 'OK'.
Querying the Historian
Canary offers 9 tables to query against: aggregates, assetinstances, assettypes, assettypetags, currentdata, data, tagproperties, tags, and views.
For a simple test of connectivity, use the following query to return a list of all available aggregates and their descriptions:
The ODBC connector was built so that the machine pulling the data from the historian would not be overloaded with data. In most instances you may need to make a query using the 'openquery' function. This function will help define the parameters and keep the system from bogging down.
Here is an example requesting an hourly average over a 1-day period using openquery where 'CanaryHistorian' is the machine name, 'Data Generation' is the dataset, and 'Random' is the beginning of the tag name: