Jetbrains Rider connection string to Ubuntu SQL Server

0

I have installed SQL server on my ubuntu ( 17.04 ) and it is running perfectly fine. I am using the Jetbrains Rider for my C# development work and I can connect to my local SQL Server instance via the Database tool comes with Jetbrains Rider.

enter image description here

But when I'am trying to connect to the same DB from my App it is raising 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: 25 - Connection string is not valid) ---> System.Net.Sockets.SocketException (0x80004005): Success

Following is my connection string in my appsettings.json file

"ConnectionStrings": {
"DefaultConnection": "Data Source=localhost\\sqlexpress:1433;Database=MyDb;User Id=SA;Password=MyPasswd;"

},

I tried to connect with out the port number and "Initial Catalog" instead of "Database" in connection string as well.

How can I set up my connection string properly?

sql-server
ubuntu
connection-string
rider
asked on Stack Overflow Oct 25, 2017 by user3496510

2 Answers

0

I had the same issue and found that in docker the linux version of sql server exposes itself on port 1401!! not the standard 1433 which seemed to be my issue althought you do seem to connect ok on the rider side.. strange

answered on Stack Overflow Feb 4, 2018 by Richard Parkins
0
Data Source=localhost\\sqlexpress:1433;Database=MyDb;User Id=SA;Password=MyPasswd;

Try a comma instead of a semi colon

Data Source=localhost\\sqlexpress,1433;Database=MyDb;User Id=SA;Password=MyPasswd;

Let me do a full example for future readers:

If I run the below: (on ubuntu)

sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password1#" \
   -p 1455:1433 --name sql1 \
   -d mcr.microsoft.com/mssql/server:2017-latest

My connection string is:

{
  "ConnectionStrings": {
    "MyConnectionString": "Data Source=localhost,1455;Database=master;User Id=sa;Password=Password1#;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  },
  "AllowedHosts": "*"
}

obviously, you probably don't want to actually use "master" db, but for testing it early, its acceptable.

answered on Stack Overflow Aug 21, 2019 by granadaCoder

User contributions licensed under CC BY-SA 3.0