0

Querying the Historian using a Linked Server in Microsoft SQL Server (version 22)

Configuring the Linked Server

  1. Ensure the ODBC Service is installed/licensed on the Canary Historian and the ODBC client is installed on the SQL server.
  2. Open Microsoft SQL Server Management Studio and right-click 'Linked Servers' to create a 'New Linked Server'.                                         
  3. Name the linked server. In this example, we are using 'CANARY'.
  4. Select 'Microsoft OLE DB Provider for ODBC Drivers' from the Provider drop-down list.
  5. Set the Data source to 'CanaryODBCClient'.
  6. 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.)
  7. 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:

select * from openquery(CANARY, 'select * from aggregates')

 

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:

select * from openquery(CANARY,
          'select * from data
          where tag_name like ''HistorianMachineName.Data Generation.Random%''
          and aggregate_interval=''01:00:00''
          and aggregate_id=''TimeAverage2''
          and time_stamp>=''9/26/2021''
          and time_stamp<=''9/26/2021''')

2 replies

null
    • System Engineer
    • laura_perez
    • 1 yr ago
    • Reported - view

    Hello,

    I have tried to query canary as a linked server from SQL Management studio and I only can see the column names, without data.

    I have used the following query:

    select * from openquery(CANARY, 'select * from aggregates')

      • smason
      • 1 yr ago
      • Reported - view

      Laura The ODBC client makes an anonymous connection by default. Is the ANONYMOUS LOGON user listed in the Views>Configuration>Access ALLOW list? If not, you could try adding that user back in and try again. If you are wanting to connect securely, you can specify the user within the security tab shown in Step 6. This user needs should reside on the ALLOW list as well within Views.