1

I've been stuck on this error for several days and I've already tried a lot of things. I am deploying my MVC C# application under .NET6 Entity FrameWork on my local machine. I rather succeeded and my application is available from my machine. However, whenever I try to access my DB, I get the following error:

SqlException: Cannot open database "COBRA_DB" requested by the login. The login failed.
Login failed for user 'AUTORITE NT\Système'.

I documented myself on NT Authority and I understood that it was necessary to add this profile for permissions. I open SQL Manager Studio, I add the following profiles: (French version but equivalent I suppose):

AUTORITE NT\SERVICE LOCAL

AUTORITE NT\Système

(NT AUTHORITY/LOCAL SERVICE | NT AUTHORITY/System) enter image description here

Then I gave them the necessary permissions :

enter image description here enter image description here

However it is still impossible for me to access my DB from my local server. Can you help me, I'm a bit lost. Thanks

1 Answers1

2

After you deploy your project, you could't use the connection string like (localdb)\\mssqllocaldb. It just for development environment.

Usually we should connect the db like below. The format should be like :

Data Source=XXX.windows.net,1433;Initial Catalog=db;Persist Security Info=False;User ID=user;Password=mypassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;

Connection Timeout=30;

enter image description here

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • I understand, but how am I going to see the errors of my database without the development mode in this case? They are hidden if I understand correctly. However, thank you for your response and your time. – Jules Valignat Jun 08 '22 at 13:18
  • @JulesValignat Usually we create COBRA_DB_Development and COBRA_DB. COBRA_DB_Development can be used for team collaborative development. The previous one can only be tested on your own machine. – Jason Pan Jun 08 '22 at 13:21
  • Thanks a lot for your experience. Have a nice day. – Jules Valignat Jun 08 '22 at 13:25
  • @JulesValignat If my reply is helpful, please accept it as answer(click on the mark option beside the reply to toggle it from greyed out to fill in.), see https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Jason Pan Jun 08 '22 at 13:28