Microsoft SQL Server

Data Sources ››
Parent Previous Next

Creating a SQL DataSource

Use the Sources Manager Tree or the DataNode Configuration dialogue to Create or Edit a new SQL DataSource.

Configuring the SQL DataSource

To setup a Microsoft SQL Server DataSource:

Configuring the SQL DataView(s)

To add a new DataView click the New DataView button. You can edit existing DataView by selecting it in the grid and clicking Edit, or by double clicking the DataView in the grid.

TIPS


Use the Object Browser to get a list of the objects (table, views, columns etc.) that you currently have access to on the server and add them to the query from a selection. This reduces the risk of misspelling.

Check out the SQL walk through section for configuration and query examples.


NOTE


The DataView is now configured and can be used in read only mode.

SQL Server and Azure DataViews also support Write operations, custom Actions and change Notifications. If you want to configure this functionalities, read on.

Defining Writing Permissions

If necessary you can also specify how to write data back to the server.

In the Write tab, for each column where you want to allow users to edit the data, you must specify:

TIPS


You can click the See Permissions... button to open the Object Browser and get a list of columns with parent table, table key(s) and permissions from the server. These columns can be added to the list from the Object Browser directly. This reduces the risk of misspelling and errors, and already includes the table key(s) defined for the table.

You can find examples of column permissions set-up in the SQL walk through section.


warning


Do not use generic SQL Logins with high permissions for all the users or they will be able to grant themselves permissions on other columns by modifying this section of the configuration.

This setup cannot override the permissions defined on the server. If information is provided for a column that a login is not authorised to update, the logged in user will receive an error message when trying to edit that column from the grid.

It is therefore highly recommended to restrict logins permissions as much as possible on the server.


NOTE


It is not imperative for the ID Column(s) to be the primary key(s) of the table, it doesn't even need to uniquely identify records. But all records that have values matching those of the selected rows for the ID Column(s) will be updated as well.

It is not necessary, but good practice.


Defining Allowed Values

By default, when editing a column, the user can enter any value of the proper data type. By defining Allowed Values for a column, you restrict the user input and the editing form will display a drop down with the values you defined only.

To define Allowed Values for a column:

Create, Delete and other Advanced Operations

Advanced Operations, or Actions, allow you to associate buttons in BimSens's interface to stored procedures or SQL statements on the server.

To create an Action, open the Advanced tab and click the New Action button.

In the Action Configuration dialogue:

TIPS


You can click the Standard Commands... button to open the Object Browser and automatically get SQL query for standard INSERT and DELETE statements for all tables on the database. This reduces the risk of misspelling and errors, and already includes the table key(s) defined for the table.

To learn more about Actions and Action Types, refer to the Actions section, or check the SQL walk through section to see some action examples.


If the Command requires parameters you can specify them in the Command Parameters grid.

You can either enter Parameters manually, or click the Infer Parameters button to try getting automatic configuration.

For each parameter you must specify:

To learn more about Parameters, Editing & Default Modes, refer to the Actions section, or check the SQL walk through section to see some action examples.


warning


Do not use generic SQL Logins with high permissions for all the users or they will be able to execute potentially harmful code by modifying this section of the configuration.

Set up the SQL Server for Notifications

In addition to read and write access, SQL DataSources support change notifications: when a modification is made to the database, a notification is sent to BimSens to refresh its data. Reaction to notifications include Automatic Refresh of the data and re-applying the Auto Colour Filter.

The Notifications system for SQL DataSources relies on SqlDependencies which requires some options to be activated on the database and elevated permissions for the user:

warning


These are a lot of permissions to give to a user that is not trust worthy, consider enclosing them into a schema to reduce the damage the user could do.


The SQL command below can be executed on a SQL database to do the complete set up, for the database called NOTIFICATION DEMO and the SQL Login DependencyUser.

Change the database name, user, role and schema as required for your configuration.

(Source: http://www.codeproject.com/Articles/12862/Minimum-Database-Permissions-Required-for-SqlDepen)


USE master

--Enable the Service Broker

ALTER DATABASE [NOTIFICATION DEMO] SET ENABLE_BROKER

GO


--Create the Server Login

--(Only if you are not using an existing login)

CREATE LOGIN [DependencyUser] WITH PASSWORD=N'BimSensRocks',

DEFAULT_DATABASE=[NOTIFICATION DEMO],

           CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF

GO


USE [NOTIFICATION DEMO]

--Create the Database User for the server Login

--(Only if you are not using an existing user)

CREATE USER [DependencyUser] FOR LOGIN [DependencyUser]

GO


--Create a default schema for the user rather than giving him ownership of the dbo

CREATE SCHEMA [DependencyUserSchema] AUTHORIZATION [DependencyUser]

ALTER USER [DependencyUser] WITH DEFAULT_SCHEMA = [DependencyUserSchema]


--Create a role and assign permissions

EXEC sp_addrole 'sql_dependency_role'

EXEC sp_addrolemember 'sql_dependency_role', 'DependencyUser'


GRANT CREATE PROCEDURE TO [sql_dependency_role]

GRANT CREATE QUEUE TO [sql_dependency_role]

GRANT CREATE SERVICE TO [sql_dependency_role]

GRANT REFERENCES ON

CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]

TO [sql_dependency_role]

GRANT SUBSCRIBE QUERY NOTIFICATIONS TO [sql_dependency_role]

GRANT RECEIVE ON QueryNotificationErrorsQueue TO [sql_dependency_role]

GRANT VIEW DEFINITION TO [sql_dependency_role]

GRANT SELECT to [sql_dependency_role]


TIPS


Alternatively if you don't really give a damn about security, you can simply make the database user a member of the db_owner role. But that's not very secured...

Activate Notifications

Once the database is set up, the notification needs to be configure for the DataView.

warning


There are rules and limitations for Queries to be eligible to change Notifications:

  • the command must use 2 parts names e.g. dbo.TableName instead of TableName
  • the command cannot use * for fields selection e.g. SELECT C1, C2 FROM dbo.TableName instead of SELECT * FROM dbo.TableName
  • it cannot use Views and has restrictions on Stored Procedures
  • it cannot use aggregate functions (SUM, AVG, COUNT etc.)

See the complete list of restrictions: http://msdn.microsoft.com/en-us/library/aewzkxxh.aspx


This completes the configuration on the DataView side, but for BimSens to react to notifications from the DataView the corresponding option needs to be activated. Close the view configuration dialogue, and from the Options dialogue go to the Refresh tab and active the option Refresh when the View notifies of Changes.


Check out the Set up Notifications on SQL Server Source walk through for an example.