I have pulled the docker for SQL Server and run it using this command.
docker run -e 'ACCEPT_EULA=Y' -e "SA_PASSWORD=12345678Aa" -e "MSSQL_PID=Express" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest-ubuntu
When I try to run my project in Visual Studio via IIS Express,it's running correctly.
But I try to run it using docker it gives me connection error.
My coonection string is : Server=ms-sql-server,1433;Database=aspnet-WebApplication-4167B36A-F12A-4C4C-AEAC-5B6C8ADA1384;Trusted_Connection=False;User Id=SA;Password=12345678Aa
The connection error is : Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "aspnet-WebApplication-4167B36A-F12A-4C4C-AEAC-5B6C8ADA1384" requested by the login. The login failed. Login failed for user 'sa'.
How to configure my SQL Server docker in VS 19 in my project?
The app and mssql service are likely to be on different networks when you use it in a docker container, considering that you have not defined it.
A quick way to resolve this is to change the name of your service in the connection string by its IP number, in the appsettings
, as follows:
"ConnectionString":"Server=192.168.0.27,1433;Database=aspnet-WebApplication-4167B36A-F12A-4C4C-AEAC-5B6C8ADA1384;Trusted_Connection=False;User Id=SA;Password=12345678Aa"
User contributions licensed under CC BY-SA 3.0