Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Connect to SQL Analysis Services Data from Blazor Apps
Build ASP.NET Core Blazor C# apps that integrate with real-time SQL Analysis Services data using standard SQL.
Blazor is a framework for developing modern, client-side web UIs using .NET technology. Instead of coding in JavaScript, developers can use the familiar C# language and .NET libraries to build app UIs.
The CData ADO.NET Provider for SQL Analysis Services can be used with standard ADO.NET interfaces, such as LINQ and Entity Framework, to interact with live SQL Analysis Services data. Since Blazor supports .NET Core, developers can use CData ADO.NET Providers in Blazor apps. In this article, we will guide you to build a simple Blazor app that talks to SQL Analysis Services using standard SQL queries.
Install the CData ADO.NET Provider for SQL Analysis Services
CData ADO.NET Providers allow users to access SQL Analysis Services just like they would access SQL Server, using simple SQL queries.
Install the SQL Analysis Services ADO.NET Data Provider from the CData website or from NuGet. Search NuGet for "SQL Analysis Services ADO.NET Data Provider."
Create a SQL Analysis Services-Connected Blazor App
Start by creating a Blazor project that references the CData ADO.NET Provider for SQL Analysis Services
- Create a Blazor project on Visual Studio.
- From the Solution Explorer, right click Dependencies, then click Add Project Reference.
- In the Reference Manager, click the Browse button, and choose the .dll file of the installed ADO.NET Provider (e.g. System.Data.CData.SSAS.dll, typically located at C:\Program Files\CData\CData ADO.NET Provider for SQL Analysis Services\lib etstandard2.0).
SELECT SQL Analysis Services Data from the Blazor App
- Open the Index.razor file from the Project page.
- In a SSASConnection object, set the connection string:
To connect, provide authentication and set the Url property to a valid SQL Server Analysis Services endpoint. You can connect to SQL Server Analysis Services instances hosted over HTTP with XMLA access. See the Microsoft documentation to configure HTTP access to SQL Server Analysis Services.
To secure connections and authenticate, set the corresponding connection properties, below. The data provider supports the major authentication schemes, including HTTP and Windows, as well as SSL/TLS.
-
HTTP Authentication
Set AuthScheme to "Basic" or "Digest" and set User and Password. Specify other authentication values in CustomHeaders.
-
Windows (NTLM)
Set the Windows User and Password and set AuthScheme to "NTLM".
-
Kerberos and Kerberos Delegation
To authenticate with Kerberos, set AuthScheme to NEGOTIATE. To use Kerberos delegation, set AuthScheme to KERBEROSDELEGATION. If needed, provide the User, Password, and KerberosSPN. By default, the data provider attempts to communicate with the SPN at the specified Url.
-
SSL/TLS:
By default, the data provider attempts to negotiate SSL/TLS by checking the server's certificate against the system's trusted certificate store. To specify another certificate, see the SSLServerCert property for the available formats.
You can then access any cube as a relational table: When you connect the data provider retrieves SSAS metadata and dynamically updates the table schemas. Instead of retrieving metadata every connection, you can set the CacheLocation property to automatically cache to a simple file-based store.
See the Getting Started section of the CData documentation, under Retrieving Analysis Services Data, to execute SQL-92 queries to the cubes.
For example: User=myuseraccount;Password=mypassword;URL=http://localhost/OLAP/msmdpump.dll;
-
HTTP Authentication
- The code below creates a simple Blazor app for displaying SQL Analysis Services data, using standard SQL to query SQL Analysis Services just like SQL Server.
@page "/" @using System.Data; @using System.Data.CData.SSAS; <h1>Hello, world!</h1> Welcome to your Data app. <div class="row"> <div class="col-12"> @using (SSASConnection connection = new SSASConnection( "User=myuseraccount;Password=mypassword;URL=http://localhost/OLAP/msmdpump.dll;")) { var sql = "SELECT Fiscal_Year, Sales_Amount FROM Adventure_Works"; var results = new DataTable(); SSASDataAdapter dataAdapter = new SSASDataAdapter(sql, connection); dataAdapter.Fill(results); <table class="table table-bordered"> <thead class="thead-light"> <tr> @foreach (DataColumn item in results.Rows[0].Table.Columns) { <th scope="col">@item.ColumnName</th> } </tr> </thead> <tbody> @foreach (DataRow row in results.Rows) { <tr> @foreach (var column in row.ItemArray) { <td>@column.ToString()</td> } </tr> } </tbody> </table> } </div> </div>
- Rebuild and run the project. The ADO.NET Provider renders SQL Analysis Services data as an HTML table in the Blazor app.
At this point, you have a SQL Analysis Services-connected Blazor app, capable of working with live SQL Analysis Services data just like you would work with a SQL Server instance. Download a free, 30-day trial and start working with live SQL Analysis Services data in your Blazor apps today.