Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot connect to SQL database using Blazor and Entity Framework

I’m trying to setup a simple Blazor website that connects to a SQL Server database and I can’t seem to get it to work, I get an error:

System.PlatformNotSupportedException: Strings.PlatformNotSupported_DataSqlClient

when trying to query any of the database entities. Connecting to the same database and using the same DBContext works fine from a unit testing projects, I just can’t make it work using Blazor.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In my program.cs I have:

builder.Services.AddDbContext<IntegrationDBContext>(options => options.UseSqlServer(@"MyConnString"));

I even tried using an in-memory provider, which worked fine. I’m using .NET 6 and connecting to an Azure based SQL (although I did try connecting to a LocalDB instance, with the same results).

Thanks!

>Solution :

The MS-SQL Client software uses a TCP socket based protocol that is indeed "not supported" on WebAssembly.

You would need a Db with an HTTP based API but then be very aware that your credentials will be public. A Web based Client is not secure.

This is why all SPA apps that need a backend Database use an API server for Db access. Take a look at the Blazor Wasm + Hosted template, see if that works for you.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading