30

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!

MikePR
  • 2,786
  • 5
  • 31
  • 64
  • 14
    Found how to connect to the Docker instance of SQL Server. I had to set up the Trusted_Connection=false. After that I was able to connect when running my ASP.Net core app. – MikePR Oct 29 '18 at 17:10
  • Thanks! I wasted so much time on this one and that fixed it! – Dontreadonme Jan 04 '19 at 06:58

7 Answers7

37

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.

Randy Eppinger
  • 1,054
  • 13
  • 23
14

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

Hicham Mounadi
  • 429
  • 6
  • 8
4

Solved mine by setting Trusted_Connection=False

4

I was able to solve mine by removing Trusted_Connection

Obainodtq
  • 51
  • 1
  • 3
3

I ran the connection string as follows and it worked

"ConnectionStrings": {
    "DevConnection": "Server=localhost,1433;Database=TarjetaCreditoDB;User Id=sa;Password=myPassw0rd;MultipleActiveResultSets=True;"
  }
jonanv
  • 39
  • 2
1

Below string worked for me.

 Server=sql-server-db,1433;Database=EMP_DB_V2;User=SA;Password=Test_pwd@786;Trusted_Connection=False;MultipleActiveResultSets=True;
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 31 '23 at 22:00
0

I ran the connection string as follows and it worked

"ConnectionStrings": {
    "DefaultConnection": "Server=localhost,1433; Database=ERPDb; User=sa; Password =*****; Trusted_Connection=false; TrustServerCertificate=true;"
  },
HiroCereal
  • 550
  • 1
  • 11