Reputation: 23
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.
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!
Upvotes: 2
Views: 2466
Reputation: 273244
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.
Upvotes: 1