My Blazor Server Project cannot connect to SQL Server

-1

I created a Blazor Server Project but when I publish it locally and go to the page which has the table that is connected to the database, The table does not appear. Instead, I get the 2 error messages shown below.

Error message 1:

blazor.server.js:21 [2021-05-11T14:22:46.648Z] Error: Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SNI_PN11, error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name is invalid. )

Error message 2:

Failed to load resource: the server responded with a status of 500 ()

Below is the code in my appsettings.json file:

{
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-BlazorServerCrud-A4AB9537-A41F-429B-ACBC-A759B58FF0EC;Trusted_Connection=True;MultipleActiveResultSets=true",
    "myconn": "server=(localdb)\\\\mssqllocaldb; database=BlazorServerCRUD;Trusted_Connection=True;",
  },
  "Logging": 
  {
    "LogLevel": 
    {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  }
}

And below is the code in the appsettings.Development.json file:

{
  "DetailedErrors": true,
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  }
}

What should I do so that my site connects to the SQL Server and the table appears when I publish the project?

asp.net
sql-server
blazor
blazor-server-side
asked on Stack Overflow May 11, 2021 by Saad • edited May 11, 2021 by Saad

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0