Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect ASP.Net Core to a SQL Server Docker container on Mac

I am developing an ASP.Net core MVC application using Visual Studio 2017 on Mac. However, I am facing some problems to connect to an instance of SQL Server that is running on a Docker container.

This is the connection string I'm using:

"ConnectionStrings": {
    "myCustomConnString": "Server=localhost;Database=myDataBase;User Id=sa;Password=myPassw0rd;Trusted_Connection=True;MultipleActiveResultSets=true"
  }

And this is the error I am getting:

Cannot authenticate using Kerberos. Ensure Kerberos has been initialized on the client with 'kinit' and a Service Principal Name has been registered for the SQL Server to allow Kerberos authentication. ErrorCode=InternalError, Exception=Interop+NetSecurityNative+GssApiException: GSSAPI operation failed with error - An unsupported mechanism was requested (unknown mech-code 0 for mech unknown).

Using SQL Operation Studio, Azure Data Studio and/ or Visual Studio Code and passing the same parameters I can connect to the docker instance of SQL Server. But not when running the ASP.Net core app. So, I'm not sure if I am missing any additional parameter for the connection string.

Does anyone have try this before?

Regards!

like image 701
MikePR Avatar asked Oct 27 '18 16:10

MikePR


People also ask

Can ASP NET application be run in Docker container?

Choose the docker option to run the application as shown in the following image. After clicking on the docker option, it will build code, create a docker image as well as a docker container and run the application inside the docker container without using the docker commands on the windows command prompt.


Video Answer


2 Answers

I know that @MikePR 's comment serves as the answer, but I wanted to provide a more complete answer for the issue I had. I could not get dotnet ef database commands to execute evan after using the connection string with Trusted_Connection=false. With the help of this article, I was able to use this connection string:

"ConnectionStrings": {
    "myCustomConnString": "Server=localhost,1433\\Catalog=myDatabase;Database=myDatabase;User=username;Password=MYSecurePWD;"
  }

Now, my migrations run against the SQL Server in the docker container. Note that the article did not include using Trusted_Connection=false. I assume that false is the default.

like image 102
Randy Eppinger Avatar answered Sep 29 '22 16:09

Randy Eppinger


I got the same issue, and it works simply by deleting Trusted_Connection=True; from the connection string

like image 24
Hicham Mounadi Avatar answered Sep 29 '22 16:09

Hicham Mounadi