![]() |
VOOZH | about |
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 AlloyDB can be used with standard ADO.NET interfaces, such as LINQ and Entity Framework, to interact with live AlloyDB 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 AlloyDB using standard SQL queries.
CData ADO.NET Providers allow users to access AlloyDB just like they would access SQL Server, using simple SQL queries.
Install the AlloyDB ADO.NET Data Provider from the CData website or from NuGet. Search NuGet for "AlloyDB ADO.NET Data Provider."
๐ Install ADO.NET AlloyDB Provider from NuGet.Start by creating a Blazor project that references the CData ADO.NET Provider for AlloyDB
The following connection properties are usually required in order to connect to AlloyDB.
You can also optionally set the following:
Standard authentication (using the user/password combination supplied earlier) is the default form of authentication.
No further action is required to leverage Standard Authentication to connect.
There are additional methods of authentication available which must be enabled in the pg_hba.conf file on the AlloyDB server.
Find instructions about authentication setup on the AlloyDB Server here.
This authentication method must be enabled by setting the auth-method in the pg_hba.conf file to md5.
This authentication method must be enabled by setting the auth-method in the pg_hba.conf file to scram-sha-256.
The authentication with Kerberos is initiated by AlloyDB Server when the โ is trying to connect to it. You should set up Kerberos on the AlloyDB Server to activate this authentication method. Once you have Kerberos authentication set up on the AlloyDB Server, see the Kerberos section of the help documentation for details on how to authenticate with Kerberos.
For example: User=alloydb;Password=admin;Database=alloydb;Server=127.0.0.1;Port=5432
@page "/"
@using System.Data;
@using System.Data.CData.AlloyDB;
<h1>Hello, world!</h1>
Welcome to your Data app.
<div class="row">
<div class="col-12">
@using (AlloyDBConnection connection = new AlloyDBConnection(
"User=alloydb;Password=admin;Database=alloydb;Server=127.0.0.1;Port=5432"))
{
var sql = "SELECT ShipName, ShipCity FROM Orders WHERE ShipCountry = 'USA'";
var results = new DataTable();
AlloyDBDataAdapter dataAdapter = new AlloyDBDataAdapter(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>
At this point, you have a AlloyDB-connected Blazor app, capable of working with live AlloyDB data just like you would work with a SQL Server instance. Download a free, 30-day trial and start working with live AlloyDB data in your Blazor apps today.
Download a free trial of the AlloyDB Data Provider to get started:
Download NowLearn more:
๐ AlloyDB IconRapidly create and deploy powerful .NET applications that integrate with AlloyDB.