1

I have the following docker-compose.yml:

version: "3.9"

services:
    # Database instance
    mssql:
      image: mcr.microsoft.com/azure-sql-edge:latest
      volumes:
        - events_mssql:/var/opt/mssql
      ports:
        - 1433:1433
      environment:
        - ACCEPT_EULA=1
        - MSSQL_SA_PASSWORD=Passw@rd

volumes:
    events_mssql:

setup.sql:

CREATE DATABASE $(MSSQL_DB);
CREATE DATABASE $(MSSQL_DB_AUDIT_LOG);
GO
USE $(MSSQL_DB);
GO
CREATE LOGIN $(MSSQL_USER) WITH PASSWORD = '$(MSSQL_PASSWORD)';
GO
CREATE USER $(MSSQL_USER) FOR LOGIN $(MSSQL_USER);
GO
ALTER SERVER ROLE sysadmin ADD MEMBER [$(MSSQL_USER)];
GO

enter image description here

Here is the running container:

enter image description here

I am trying to connect to the database through the Visual Studio Code extension:

Using this connection string: Server=http://localhost:1433/;Database=master;User Id=sa;Password=Passw@rd;

I am getting the error:

mssql: Error: Unable to connect using the connection information provided. Retry profile creation?

enter image description here

What am I doing wrong here?

qqqqqqq
  • 1,831
  • 1
  • 18
  • 48
  • 2
    SQL server doesn’t use http. Check your connection string. – David Browne - Microsoft Apr 12 '22 at 22:52
  • @DavidBrowne-Microsoft, the `Server=localhost:1433;Database=master;User Id=sa;Password=Passw@rd;` connection string does not work either. The same error is shown. – qqqqqqq Apr 12 '22 at 22:54
  • If you're using [ODBC Driver 18 for SQL Server](https://techcommunity.microsoft.com/t5/sql-server-blog/odbc-driver-18-0-for-sql-server-released/ba-p/3169228) or later also try adding `TrustServerCertificate=yes;` to your connection string after removing http. – AlwaysLearning Apr 12 '22 at 23:09
  • @AlwaysLearning, the `Server=localhost:1433;TrustServerCertificate=yes;Database=events_service;User Id=SA;Password=Passw@rd;` connection string does not work as well. :( – qqqqqqq Apr 12 '22 at 23:13
  • Also try `Server=tcp:127.0.0.1,1433;` with a comma `,` before the port number instead of a colon `:`. Depending on your network configuration and default protocols `localhost` could resolve to either `127.0.0.1` (IPv4) or `::1` (IPv6), but Docker is only listening on IPv4 ports by default. – AlwaysLearning Apr 13 '22 at 00:08
  • Also, have you checked the container's log output for errors (by clicking on it in the Docker Desktop GUI)? The container may be considered up by Docker, but the SQL Server service inside it may not be listening or accepting connections for various reasons. – AlwaysLearning Apr 13 '22 at 00:09
  • @AlwaysLearning, the `Server=tcp:127.0.0.1,1433;Database=master;MultipleActiveResultSets=true;User=sa;Password=Passw@rd;` worked just fine. Thank you. – qqqqqqq Apr 13 '22 at 08:07
  • at volumes you have some value at events_mssql or it is empty? – billysk Nov 11 '22 at 19:51

0 Answers0