skip to Main Content

I’m on ubuntu system trying to connect to my local sql server from my (ASP).net application
i configured the string connection

"ConnectionStrings": { "DefaultConnection": "Server=localhost\mssqllocaldb;Database=temaintdb;User Id=sa; Password=******;" },

also i enabled the TCP/Ip ,and allowed the port 1433, and tried a remote access to my db and it’s worked
but when i’m trying to update my database from my .net i’m facing this error :
dotnet ef database update

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: 35 - An internal exception was caught).

i already checked :
-string connection
-sql server remote access
-Firewall or network configuration
-Enabled TCP/IP protocole

chabba@chabba:~$ systemctl status mssql-server
   ● mssql-server.service - Microsoft SQL Server Database Engine
     Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor >
     Active: active (running) since Tue 2023-05-23 12:48:52 +01; 4min 16s ago
       Docs: https://docs.microsoft.com/en-us/sql/linux
    Main PID: 1158 (sqlservr)
      Tasks: 170
     Memory: 1.9G
     CGroup: /system.slice/mssql-server.service
             ├─1158 /opt/mssql/bin/sqlservr
             └─1646 /opt/mssql/bin/sqlservr
    chabba@chabba:~$ sudo ufw status
    [sudo] password for chabba: 
    Status: active
To                         Action      From
--                         ------      ----
1433                       ALLOW       Anywhere                  
1433 (v6)                  ALLOW       Anywhere (v6)             

1433                       ALLOW OUT   Anywhere                  
1433 (v6)                  ALLOW OUT   Anywhere (v6) `

2

Answers


  1. Chosen as BEST ANSWER

    yeah, that was one of the solution i found in internet, ik it sounds stupid cause i have no instance set in my server but i wanted to check it the acctual string i'm using is "ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=temaintdb;User Id=sa;Password=*********;" }, and the probleme is that in my project i've multiple appsettings, and i forgot to change the string connection in all of them. thank you for answering me


  2. From your connection string, it seems that you’re trying to connect to a SQL Server instance named "mssqllocaldb" on your localhost. The backslashes () in the instance name are used in Windows systems for SQL Server connections and not usually in Unix-based systems.

    It might be that the server instance name is incorrect, or that SQL Server on Linux doesn’t support named instances like "mssqllocaldb". On Linux, SQL Server runs as a single instance per server, and doesn’t support the concept of named instances. Therefore, specifying a named instance would result in a connection error.

    So the connection string should be:

    "ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=temaintdb;User Id=sa; Password=******;" }
    

    After you’ve made the changes, please try to connect again.

    Note: Make sure you’re not exposing your sa password and use the appropriate method to secure your connection string.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search