Cannot connect to MSSQL with Docker via VSC (MacOS) - sql-server

I am trying to connect to MSSQL via Visual Studio Code with installed mssql extension. I did pull and run SQL Server 2017 container image with Docker and I am trying to make a connection, although I do get an error:
mssql: Failed to connect: System.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: TCP Provider, error: 25 - Connection string is not valid)
---> System.Net.Sockets.SocketException (0x80004005): Undefined error: 0 at System.Data.SqlClient.SN
The container image is running - I did log on to MSSQL through terminal, but I can't with Visual Studio Code. Do I have to provide an instance as well? Where I can find it - cannot find it on docker inspect statement.
Did you guys have similar problem and maybe found a solution?

Okay I managed to solve the problem. I do connect to sql server container on 1401 port (localhost,1401 on VSC), but apparently when you start a container you need to change the password for sa. Rookie mistake :) Thanks for trying to help

Related

Unable to connect VS CODE to my SQL Server Express - getting two errors

I have installed SQL Server (mssql) extension in my VS Code then tried to connect to SQL Server Express with ./SQLEXPRESS, master, integrated log in detail. It should work perfectly as by default there's a database named "master".
But instead I get two errors:
mssql: Error: Unable to connect using the connection information
provided. Retry profile creation?
mssql: Error 3: 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: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server)
Please can anyone help me with that?
Expecting to connect VS Code with SQL Server Express

How do you connect to a SQL Server database from within a dev container?

I'm currently working on a .NET Core project. When I run the application on my local machine (Windows) I can connect to a SQL Server database using my windows credentials.
I am attempting to shift into using a devcontainer within Visual Studio Code, but when I run the same application in the container (Linux) I get an error:
An exception of type 'Microsoft.Data.SqlClient.SqlException' occurred
in Microsoft.Data.SqlClient.dll but was not handled in user code:
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'm not sure where to go from here. What did I miss?

how to fix mssql:Error 2 in vs code mssql extension?

When I have tried to connect to localhost and it was displayed the message about
"mssql:Error 2: 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:Named Pipes Provider,error 40-Could not open a
connection to SQL Server)".
How can I fix it?
I have tried to follow the solution technique given by "Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?" but i can't find the location of vscode mssql extension configuration tool and SQL Server Configuration Manager?
You may be changed your computer name. if you changed your computer name then back to set initial name of computer. Then restart your Sql Server(MSSQLSERVER)service.

A network related or instance specific error on Sql Server 2012

I'm getting error whenever I connect to the instance(DESKTOP-0LFC1LP) on Sql Server. I'm using Sql server 2012.
I don't know what's the reason but whenever I install Sql server , It works perfectly for a day or two and after that it starts giving me this error.
I can solve this by re-installing Sql and it will work fine but again only for a day. I want a permanent solution to this. And please also tell why it works after I reinstall it?
Your help would be appreciated!
Error says:
TITLE: Connect to Server
Cannot connect to DESKTOP-0LFC1LP.
ADDITIONAL INFORMATION:
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: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
(Microsoft SQL Server, Error: 2)
The system cannot find the file specified

A network-related or instance-specific error occurred while establishing a connection to SQL Server 2014

This error was returned when I tried to connect with server.
Error description is:
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: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified) (Microsoft SQL Server, Error: -1)
First you need to check whether SQL SERVER service is running in your system or not .For checking follows below steps in Windows.
Step 1 : Type "window" button + R ,This will open Run prompt.
Step 2: Type "services.msc" in Run prompt and hit the enter.
Step 3: Find SQL SERVER service from there.
Step 4.Start this service.
Following these steps, I have resolved this problem in my machine.
Thanks
Check your SQL Server Service is Running or not
if the server is in remote location check port 1433 is not blocked by the firewall.
if this is not the default instance, Check SQL Server Browser is running or not
Check the network connection on client PC, and verify the connection to the server using PING or TELNET
Check whether TCP/IP and Named Pipes are enabled or not.
for more details Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?
To solve this 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 Go to Sql Server Configuration Manager>>Sql Server Services Sql Server>>Right click on the Sql Server(MSSQLSERVER) and Start the Process.As show belowenter image description here
If you are trying to connect to your Sql Server running on MacOS via Docker, then make sure that Sql Docker container is running and then you will be able to connect to your Sql Server using Azure Data Studio as shown in attached image Sql Container inside Docker

Resources