VenturaSQL 3.2

VenturaSQL 3.2 is available for download.

When opening an auto-generated recordset in the editor, a warning is displayed that any changes to the recordset will be overwritten at code-generation time. If you want to modify an auto-generated recordset, copy it to a different folder first.

Two new NuGet packages have been added.

VenturaSQL.NET5Runtime

The runtime for .Net 5.0. Works with .Net 5.0 or higher, Blazor WebAssembly on .Net 5.

For Blazor WebAssembly on .Net Core 3.1 you need to use the runtime for .Net Standard 2.0.

VenturaSQL.NET5Webserver

The webserver runtime for .Net 5.0. Works with ASP.NET Core on .Net 5.0 or higher.

VenturaSQL 3.0 with Blazor WebAssembly support

I am happy to announce that VenturaSQL 3.0 is ready and can be downloaded from venturatools.com.

Follow the instructions on https://venturatools.com/ProductSqlForBlazor

When everything is installed you can create a new Ventura SQL (.venproj) project and select the Blazor WebAssembly template:

With Transactional.ExecSql(), the SQL statement(s) for the recordset will be executed on the server, and the resultset(s) returned to Blazor WebAssembly:

The recordset definition in Ventura SQL Studio. The “GetAll” and “PriKey” recordsets are generated automatically by Ventura SQL:

Blazor WebAssembly support

Ventura SQL 3.0 with full support for Blazor WebAssembly will be available for download next week.

Ventura SQL is the 3-tier SQL framework for C# projects where database access and web services are integrated into a fully integrated solution. Ventura replaces Web API and Entity Framework. Just enter SQL statements and Ventura will do the rest.

Ready-to-run sample Client and Server projects are included.

Ventura SQL Studio

HttpClient

The challenge in making Ventura SQL compatible with Blazor WebAssembly is the .Net HttpClient class that needs to be used for sending HTTP requests to a server.

From a Blazor WebAssembly app you cannot simply create a new instance of the HttpClient class and use it to access the server. The HttpClient in Blazor WebAssembly is implemented using the browser Fetch API and is subject to its limitations, including enforcement of the same origin policy.

For this reason a HttpClient instance can only be created by the Blazor runtime. Blazor will instantiate and configure the HttpClient to run in the sandbox environment of the browser.

In a Razor Page a HttpClient instance must be requested using the @inject statement, in the page’s code-behind the [Inject] attribute is used.

Using the dependency injection solution means that the Ventura SQL API would need to change to accept a HttpClient as a parameter instead of instantiating one itself. In order to keep the Ventura API uniform across all platforms an elegant solution was found. Whenever Ventura needs a HttpClient instance it calls a user defined method that is expected to return a proper HttpClient object. The method is assigned with VenturaConfig.SetHttpClientFactory(). Inside that method Blazor WebAssembly is asked for a HttpClient instance.

The sample Program class code below explains it all.

    public class Program
    {
        private static ServiceProvider _service_provider;

        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            builder.RootComponents.Add<App>("app");

            builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

            SetupVentura(builder);

            await builder.Build().RunAsync();
        }

        private static void SetupVentura(WebAssemblyHostBuilder builder)
        {
            _service_provider = builder.Services.BuildServiceProvider();
            VenturaConfig.SetHttpClientFactory(GetHttpClientForVenturaSQL);
            VenturaConfig.DefaultConnector = new HttpConnector("test", $"{builder.HostEnvironment.BaseAddress}Ventura.FSPRO");
        }

        private static HttpClient GetHttpClientForVenturaSQL(HttpConnector connector)
        {
            var client = _service_provider.GetService(typeof(HttpClient)) as HttpClient;
            return client;
        }
    }