Issue:
In VS Code, I created a .NET Web API application using Entity Framework. To activate .NET commands, I always have to run the following command:
export PATH="$PATH:$HOME/.dotnet/tools"
After doing this, I can successfully run migrations. However, after migration, when I try to update the database using the following command:
dotnet ef database update
I get the following error:
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: TCP Provider, error: 26 - Error Locating Server/Instance Specified)
appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=Khashayar\\SQLEXPRESS;Initial Catalog=FinanceNews;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Program.cs Injection:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
});
Installed Packages:
Microsoft.AspNetCore.OpenApi 8.0.8Microsoft.EntityFrameworkCore.Design 8.0.8Microsoft.EntityFrameworkCore.SqlServer 8.0.8Microsoft.EntityFrameworkCore.Tools 8.0.8
Additional Info:
- I am using Ubuntu Terminal.
- I am using .NET 8, SQL Server Management Studio (SSMS) 20, and SQL Server 2022 Configuration Manager.
- In SSMS, I checked "Trust Server Certificate," and encryption is set to mandatory mode.
- Services are running, and the data source name is correct (I verified this by running
hostnamein the terminal).
Troubleshooting Steps Taken:
I enabled TCP/IP, but it didn’t work.
I tried setting the data source to
KHASHAYAR\\SQLEXPRESS, but it didn’t work.I also tried
KHASHAYAR\\khash\\SQLEXPRESS, but it didn’t work either.I installed the necessary tools:
sudo apt-get update sudo apt-get install mssql-tools unixodbc-dev echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrcBut it still didn’t work. I need Help to make update command work
SQLEXPRESSto the port(s) that instance is listening on, only loads the server protocol configuration when it gets started so it needs a restart after configuration changes.